Hi guys. Im testing argolia on my laravel projetct.
I have some complex model relationships. For example my Post table has a lot of belongsTo , hasOne and hasMany functions.
I need to index data from those related tables, so I had to overwrite the toSearchableArray method in my Post model:
public function toSearchableArray()
{
$array = $this->toArray();
$array['category'] = $this->category;
$array['city'] = $this->city;
$array['pictures'] = $this->pictures;
return $array;
}
category and city tables are ‘belongsTo’ relations and data is properly indexed when creating a register but I can not make it work with pictures wich is a ‘hasMany’ relation.
When looking at the index, the pictures array is empty, however after running the
php artisan scout:import "App\Models\Post"
The image field is properly updated in the algolia index.
Is there some way to fix this ? Do you know why does it happen?
Any idea would be wellcome.
btw:
this is pictures function:
public function pictures()
{
return $this->hasMany(Picture::class, 'post_id')->orderBy('position')->orderByDesc('id');
}