erigra.
erigra.
FFilament
Created by erigra. on 3/28/2024 in #❓┊help
Access current record within Widget
Hey, I have a resource like ProductResource and I have an EditProduct page. Within EditProduct I have a Widget like ProductWidget. When on the edit page of that product like /product/1, how can I access the current record (1) from the Widget model? Can't seem to find anything about it in the docs. Thank you.
5 replies
FFilament
Created by erigra. on 3/25/2024 in #❓┊help
Reusing same Resource in multiple panels?
Hey, I'm building a multi tenant site, and I have 2 panels - the admin panel and tenant panel. I want to reuse the same Resource (or is that bad?) in both panels, but the permissions should be different. Admin panel would require view_any permission while the tenant panel should have "manage_own" permission required to access the list view of the resource. I'm thinking I can add the canViewAny() method on the resource and conditionally check the current panel, but it seems it is not possible to get current panel? Something like this:
public static function canViewAny(): bool
{
return currentPanel === 'admin' ? $user->can('view_any') : $user->can('manage_own');
}
public static function canViewAny(): bool
{
return currentPanel === 'admin' ? $user->can('view_any') : $user->can('manage_own');
}
Or what would be the suggest approach for this?
1 replies
FFilament
Created by erigra. on 10/27/2023 in #❓┊help
Creating global blocks?
Is it possible to create global blocks using the Blocks, that can then be attached to different Resources? Example:
Builder\Block::make('address')
->schema([
TextInput::make('street')
->label('Street')
->required(),
TextInput::make('zipcode')
->label('Zipcode')
->required(),
])
Builder\Block::make('address')
->schema([
TextInput::make('street')
->label('Street')
->required(),
TextInput::make('zipcode')
->label('Zipcode')
->required(),
])
And then I can simply add an address block to different resources? If so where would the block be defined, and how would it be attached? I can't find anything about this in docs.
6 replies
FFilament
Created by erigra. on 10/23/2023 in #❓┊help
Middleware/restriction to specific setting
Hi, new to filament and having some issues with restricting users' abilities to edit specific settings. As a background I'm using spatie's laravel-permission package along with the spatie roles plugin for filament. Now the permissions are working well for things like "edit user" etc - but, i'd like to create a specific rule for a specific field in the user resource, but can't find how to do that. So for example I have a specific field that is maybe "user_email", and then I'd like to have it so that an admin might have the permission to "edit user", but also need the permission to "edit user email", otherwise the email field should be hidden. Note: I'm not really looking for a solution specific for spatie although that's great, but mainly just the generally approach that should be used to go about doing this. Basically looking for something like this: Forms\Components\TextInput::make('email') ->email() ->middleware($user->can('edit user email') Any pointers on what I could use (instead of ->middleware(), since it's not available...) is much appreciated
5 replies