1. Go to this page and download the library: Download anthonyedmonds/laravel-find 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/ */
anthonyedmonds / laravel-find example snippets
return [
/* The key and label for searching all models; set as false to disable */
'anything-key' => 'any',
'anything-label' => 'Anything',
/* A table that is guaranteed to exist */
'base-table' => 'users',
/* Which models can be searched for, and its display label */
'models' => [
'users' => \App\Models\User::class,
],
];
class Author extends Model
{
use Findable;
public static function findDisplayLabel(): string
{
return 'Authors by name and book title';
}
public static function canBeFoundBy(?Model $user): bool
{
return true;
}
protected static function findLabel(): string
{
return 'name';
}
protected static function findDescription(): string
{
return '"An author"';
}
protected static function findLink(): string
{
return route('authors.show', '~id');
}
protected static function findFilters(Builder $query, string $term): Builder
{
return $query->where('name', 'LIKE', "%$term%");
}
}