I've installed and configured meilisearch + Laravel Scout package.
My Model:
class Post extends Model
{
use Searchable;
}
When I run php artisan scout:import 'App\Models\Post'
it returns:
Imported [App\Models\Post] models up to ID: 5
All [App\Models\Post] records have been imported.
But when I check the index, it's empty. Why?
The index is being created, but the data doesn't get imported.
The same configuration of meilisearch and Scout package, works for some other models.
I've just run into this issue myself and came across your question. I don't suppose you're specifying what should be stored in the index are you?
I.e. in your model, have you created a toSearchableArray
method like the below...
public function toSearchableArray(): array
{
return [
'name' => $this->name,
];
}
If you have, it turns out that your toSearchableArray
method must also return the primary key within the array, otherwise the record does not get indexed.
public function toSearchableArray(): array
{
return [
'id' => $this->getKey(), // this *must* be defined
'name' => $this->name,
];
}