diff --git a/composer.json b/composer.json index 9c27cfb597..ab2a3af1fd 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Models/Permission.php b/src/Models/Permission.php index 801624cff6..29369a34f2 100644 --- a/src/Models/Permission.php +++ b/src/Models/Permission.php @@ -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, + ], + ]; } \ No newline at end of file