PHP code example of esadewater / laravel-meilisearch
1. Go to this page and download the library: Download esadewater/laravel-meilisearch library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
esadewater / laravel-meilisearch example snippets
class Food extends Model implements MeiliSearchable
{
use IsMeiliSearchable;
/**
* @var string[] Mass-assignable attributes
*/
protected $fillable = [
'name',
];
/**
* Get attributes used for search
*/
public function toSearchableArray(): array
{
return [
'name' => $this->name,
];
}
}
class Recipe extends Model implements MeiliSearchable
{
use IsMeiliSearchable;
/**
* Define the searchable attributes for the model
*/
public static function getSearchableAttributes(): array
{
return [
'name',
'difficulty',
'ingredient_names',
];
}
/**
* Define the search sortable attributes for the model
*/
public static function getSortableAttributes(): array
{
return [
'name',
'difficulty',
];
}
/**
* Define the search filter attributes for the model
*/
public static function getFilterableAttributes(): array
{
return [
'difficulty',
];
}
}