<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
open-southeners / laravel-scout-advaced-meilisearch example snippets
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
class Tag extends Model
{
use Searchable;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
];
}
/**
* Get the search sortable attributes array for the model.
*
* @return array<string>
*/
public function searchableFilters(): array
{
return ['name'];
}
/**
* Get the search sortable attributes array for the model.
*
* @return array<string>
*/
public function searchableSorts(): array
{
return ['slug'];
}
}
use Illuminate\Foundation\Auth\User as Authenticatable;
use Laravel\Scout\Searchable;
use OpenSoutheners\LaravelScoutAdvancedMeilisearch\Attributes\ScoutSearchableAttributes;
#[ScoutSearchableAttributes(filterable: ['email'], sortable: ['name'])]
class User extends Authenticatable
{
use Searchable;
/**
* Get the indexable data array for the model.
*
* @return array
*/
public function toSearchableArray()
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
];
}
}