Mahdi Rezaei
Mahdi Rezaei

Reputation: 55

Laravel scout with explorer alwayse returns empty array

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());

enter image description here

Even though I have thousands of records :(

Upvotes: 2

Views: 127

Answers (0)

Related Questions