Skip to content

Commit

Permalink
add option to show/hide guard from forms using should_show_guard in c…
Browse files Browse the repository at this point in the history
…onfig (#178)

Co-authored-by: Bianchi <[email protected]>
  • Loading branch information
bianchi and Bianchi authored May 6, 2024
1 parent a17fcf1 commit 9ea7db4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 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 @@ -64,6 +64,9 @@

'default_guard_name' => null,

// if false guard option will not be show on screen. You should set a default_guard_name in this case
'should_show_guard' => true,

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

'user_name_column' => 'name',
Expand Down
4 changes: 3 additions & 1 deletion src/Resources/PermissionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public static function form(Form $form): Form
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->options(config('filament-spatie-roles-permissions.guard_names'))
->default(config('filament-spatie-roles-permissions.default_guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true))
->live()
->afterStateUpdated(fn (Set $set) => $set('roles', null))
->required(),
Expand Down Expand Up @@ -122,7 +123,8 @@ public static function table(Table $table): Table
TextColumn::make('guard_name')
->toggleable(isToggledHiddenByDefault: config('filament-spatie-roles-permissions.toggleable_guard_names.permissions.isToggledHiddenByDefault', true))
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->searchable(),
->searchable()
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true)),
])
->filters([
SelectFilter::make('models')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public function form(Form $form): Form
TextInput::make('name')
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
TextInput::make('guard_name')
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name')),
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true)),

]);
}
Expand All @@ -47,7 +48,8 @@ public function table(Table $table): Table
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
TextColumn::make('guard_name')
->searchable()
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name')),
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true)),
])
->filters([
//
Expand Down
1 change: 1 addition & 0 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static function form(Form $form): Form
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->options(config('filament-spatie-roles-permissions.guard_names'))
->default(config('filament-spatie-roles-permissions.default_guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true))
->required(),

Select::make('permissions')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function form(Form $form): Form
TextInput::make('name')
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
TextInput::make('guard_name')
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name')),
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true)),
]);
}

Expand All @@ -62,7 +63,8 @@ public function table(Table $table): Table
->label(__('filament-spatie-roles-permissions::filament-spatie.field.name')),
TextColumn::make('guard_name')
->searchable()
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name')),
->label(__('filament-spatie-roles-permissions::filament-spatie.field.guard_name'))
->visible(fn () => config('filament-spatie-roles-permissions.should_show_guard', true)),

])
->filters([
Expand Down

0 comments on commit 9ea7db4

Please sign in to comment.