Skip to content

Commit

Permalink
Improvements (#48)
Browse files Browse the repository at this point in the history
* Added option to filter permissions by models
Option to select guard names

* Added configurable filter key

* style fix

---------

Co-authored-by: Tharinda Rodrigo <[email protected]>
  • Loading branch information
tharindarodrigo and Tharinda Rodrigo authored Jun 17, 2023
1 parent 6895734 commit 46eb4fe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions config/filament-spatie-roles-permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

'default_guard_name' => null,


'model_filter_key' => 'return \'%\'.$key;', // Eg: 'return \'%\'.$key.'\%\';'

'generator' => [

'guard_names' => [
Expand Down
17 changes: 8 additions & 9 deletions src/Resources/PermissionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,6 @@ public static function form(Form $form): Form

public static function table(Table $table): Table
{
$commands = new \Althinect\FilamentSpatieRolesPermissions\Commands\Permission();
$models = $commands->getAllModels();
$checkBoxes = array_map(function (\ReflectionClass $model) {
return Checkbox::make($model->getShortName());
}, $models);

return $table
->columns([
TextColumn::make('id')
Expand All @@ -94,13 +88,18 @@ public static function table(Table $table): Table
])
->filters([
Filter::make('models')
->form($checkBoxes)
->form(function() {
$commands = new \Althinect\FilamentSpatieRolesPermissions\Commands\Permission();
$models = $commands->getAllModels();
return array_map(function (\ReflectionClass $model) {
return Checkbox::make($model->getShortName());
}, $models);
})
->query(function (Builder $query, array $data) {

return $query->where(function (Builder $query) use ($data) {
foreach ($data as $key => $value) {
if ($value) {
$query->orWhere('name', 'like', '%'.$key.'%');
$query->orWhere('name', 'like', eval(config('filament-spatie-roles-permissions.model_filter_key')));
}
}
});
Expand Down

0 comments on commit 46eb4fe

Please sign in to comment.