mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Use nicolaslopezj/searchable trait for easy model search
This commit is contained in:
+2
-1
@@ -29,8 +29,9 @@
|
||||
"laravel/ui": "^2.0",
|
||||
"league/glide-laravel": "^1.0",
|
||||
"livewire/livewire": "^1.0",
|
||||
"nicolaslopezj/searchable": "^1.0",
|
||||
"spatie/laravel-permission": "^3.11",
|
||||
"thomaswelton/laravel-gravatar": "~1.0",
|
||||
"thomaswelton/laravel-gravatar": "^1.0",
|
||||
"watson/active": "^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
namespace Filament\Models;
|
||||
|
||||
use Nicolaslopezj\Searchable\SearchableTrait;
|
||||
use Plank\Metable\Metable;
|
||||
|
||||
class Permission extends \Spatie\Permission\Models\Permission
|
||||
{
|
||||
use Metable;
|
||||
use SearchableTrait, Metable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -19,11 +20,23 @@ class Permission extends \Spatie\Permission\Models\Permission
|
||||
'guard_name',
|
||||
];
|
||||
|
||||
public static function search($query)
|
||||
{
|
||||
return empty($query) ? static::query()
|
||||
: static::where('id', $query)
|
||||
->orWhere('name', 'like', '%'.$query.'%')
|
||||
->orWhere('description', 'like', '%'.$query.'%');
|
||||
}
|
||||
/**
|
||||
* Searchable rules.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $searchable = [
|
||||
/**
|
||||
* Columns and their priority in search results.
|
||||
* Columns with higher values are more important.
|
||||
* Columns with equal values have equal importance.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
'columns' => [
|
||||
'permissions.name' => 10,
|
||||
'permissions.description' => 10,
|
||||
'permissions.id' => 1,
|
||||
],
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user