I am trying to use laravel scout with meilisearch to return results from an index for products. It doesn't work for this model however it does for my user model.
I have gone through both to try and find differences that would be causing this and can't seem to find out what the issue is.
when I run
return \App\Models\Product\Product::search('iphone')->raw();
I get the raw results from the meilisearch index.
however when i run
return \App\Models\Product\Product::search('iphone')->get();
no results show.
more information: meilisearch/meilisearch-php : 1.4.1 laravel/scout: 10.5.1
when using getKey
and getScoutKey
the correct _id
key name is returned (it is the same on the User model where search is working
there are no filtered out results or related models
Product Model
protected $primaryKey = self::ID;
public function toSearchableArray()
{
$searchable = [];
$searchable[self::ID] = $this->getAttribute(self::ID);
$searchable[self::NAME] = $this->getAttribute(self::NAME);
$searchable[self::SLUG] = $this->getAttribute(self::SLUG);
$searchable[self::MODEL_NAME] = $this->getAttribute(self::MODEL_NAME);
$searchable[self::MODEL_SUB] = $this->getAttribute(self::MODEL_SUB);
$searchable[self::MODEL_GENERATION] = $this->getAttribute(self::MODEL_GENERATION);
$searchable[self::MODEL_SIZE] = $this->getAttribute(self::MODEL_SIZE);
$searchable[self::MODEL_EXTRA] = $this->getAttribute(self::MODEL_EXTRA);
$searchable[self::BRAND_NAME] = ($this->brand) ? $this->brand->name : 'unknown';
$searchable[self::DESCRIPTION] = $this->getAttribute(self::DESCRIPTION);
return $searchable;
}
Anyone have any idea's on what may be causing this?
On another project that accesses the same meilisearch instance and databases, which is on Laravel 8 where the results were being returned using get(), rather than the project where this was failing a Laravel 10 project.
Downgrading the followin packages to match the Laravel 8 project fixed the issue, obviously this is not long term as a solution but got me going again on the feature where this was required.