Update records in a index of multiple models

Hey,
I’m using: "laravel/framework: 5.6,*", "algolia/algoliasearch-client-php": "^2.6", "algolia/scout-extended": "0.*" and "laravel/scout": "^6.1.1".

I have an Aggregator class and when I create / update a record of one of the models of the Aggregator, the records of the index aggregator aren’t been updated.

My Aggregator:

class Search extends Aggregator
{
    protected $models = [
        News::class,
        Post::class,
    ];
}

One of the models of the Aggregator:

class Post extends Model
{
    use Searchable;
    public function toSearchableArray()
    {
        $array = $this->toArray();
        $array['title'] = $this->title;
        $array['description'] = $this->short_description;
        return $array;
    }
...
}

Update in PostController

public function update(Request $request, $id)
    {
        if($request->ajax())
            return ['ok' => true];
        $post = Post::findOrFail($id);
        $post->update($request->all());
        $post->save();
        return redirect()->action('Admin\PostController@index');
    }

What am I missing? Can somebody help me?

Hey!

You are using an old version of Scout Extended. Can you update to the latest v1.9.x?

Concerning your problem, did you add the aggregator to the boot method of your service provider as specified here: https://www.algolia.com/doc/framework-integration/laravel/advanced-use-cases/multiple-models-in-one-index/?language=php#defining-aggregators?

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Search::bootSearchable();
    }

Hey Nuno! Thanks for answering.

Scout Extended v1.9.x is compatible with Scout 8.0, and I’m using 6.1.1 because it’s compatible with my actual Laravel version.

I added the bootSearcheable() method to an own service provider, but when I changed it to AppServiceProvider it started to work. :slight_smile:

Thanks!