Reputation: 55
I use Jeroen-G/Explorer for integrate with Elastic Search and Laravel Scout
I add this line to config/explorer.php
:
'indexes' => [
\App\Models\Post::class
],
after that, I update my model like bellow:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use JeroenG\Explorer\Application\Explored;
use Laravel\Scout\Searchable;
class Post extends Model implements Explored
{
use HasFactory, Searchable;
protected $fillable = ['title', 'published'];
public function mappableAs(): array
{
return [
'id' => 'keyword',
'title' => 'text',
'published' => 'boolean',
'created_at' => 'date',
];
}
public function toSearchableArray(): array
{
return [
'id' => $this->id,
'title' => $this->title,
'published' => $this->published,
'created_at' => $this->created_at,
];
}
}
and I run this command:
php artisan scout:import "App\Models\Post"
but this code return's empty array:
dd(Post::search('t')->get());
Even though I have thousands of records :(
Upvotes: 2
Views: 127