Level 1
I found the issue as the id of the model and id of the typesense indexing so it was not giving any results.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have integrated typesense with laravel scout for search functionality of a model, the indexing of the model is correct as the data is visible and searchable in typesense dashboard but when i search from the model using scout it donot returns any data the code snippet is given below.
scout.php
'model-settings' => [
Download::class => [
'collection-schema' => [
'enable_nested_fields' => true,
'fields' => [
['name' => 'title', 'type' => 'string'],
['name' => 'download_type', 'type' => 'string'],
['name' => 'download_sub_type', 'type' => 'string'],
['name' => 'created_at', 'type' => 'int32'],
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'title'
],
],
FilamentPage::class => [
'collection-schema' => [
'enable_nested_fields' => true,
'fields' => [
['name' => 'title', 'type' => 'string'],
['name' => 'title_ne', 'type' => 'string'],
['name' => 'data', 'type' => 'object'],
['name' => 'created_at', 'type' => 'int32'],
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'title'
],
],
Announcement::class => [
'collection-schema' => [
'enable_nested_fields' => true,
'fields' => [
['name' => 'title', 'type' => 'string'],
['name' => 'description', 'type' => 'string'],
['name' => 'type', 'type' => 'string'],
['name' => 'category', 'type' => 'string'],
['name' => 'created_at', 'type' => 'int32'],
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'title'
],
],
Service::class => [
'collection-schema' => [
'enable_nested_fields' => true,
'fields' => [
['name' => 'title', 'type' => 'string*'],
['name' => 'description', 'type' => 'string'],
['name' => 'department', 'type' => 'string'],
['name' => 'created_at', 'type' => 'int32'],
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'title'
],
],
Event::class => [
'collection-schema' => [
'enable_nested_fields' => true,
'fields' => [
['name' => 'name', 'type' => 'string*'],
['name' => 'description', 'type' => 'string'],
['name' => 'location', 'type' => 'string'],
['name' => 'date', 'type' => 'string'],
['name' => 'time', 'type' => 'string'],
['name' => 'category', 'type' => 'string'],
['name' => 'created_at', 'type' => 'int32'],
],
'default_sorting_field' => 'created_at',
],
'search-parameters' => [
'query_by' => 'name'
],
],
],
Event.php (model)
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
use Spatie\Translatable\HasTranslations;
class Event extends Model
{
use HasFactory, HasTranslations, Searchable;
protected $fillable = [
'name',
'slug',
'event_category_id',
'description',
'date',
'time',
'location',
'map',
'attachment',
'registrant',
'gallery',
'is_published',
'is_approved',
];
public $translatable = [
'name',
'description',
'location',
];
protected $casts = [
'name' => 'array',
'registrant' => 'array',
'gallery' => 'array',
];
public static function boot()
{
parent::boot();
static::creating(function ($event) {
$event->slug = str()->slug($event->name);
});
}
public function attachment()
{
return $this->belongsTo(Media::class, 'attachment');
}
// public function media(): MorphMany
// {
// return $this->morphMany(MediaItem::class, 'mediable')->orderBy('order');
// }
// public function event_gallery(): BelongsToMany
// {
// return $this->belongsToMany(Media::class, 'media_event', 'event_id', 'media_id')->withPivot('order')->orderBy('order');
// }
public function category()
{
return $this->belongsTo(EventCategory::class, 'event_category_id');
}
public function toSearchableArray()
{
return [
'name' => $this->name,
'location' => $this->location,
'description' => $this->description,
'date' => $this->date,
'time' => $this->time,
'category' => $this->category->title ?? '',
'created_at' => $this->created_at->timestamp,
];
}
}
Please or to participate in this conversation.