H4L1M
H4L1M
FFilament
Created by H4L1M on 5/1/2025 in #❓┊help
How to authorize ManageRelatedRecords viewAny based on parent record in Filament?
Hi folks — I’m trying to manage viewAny authorization for a ManageRelatedRecords page, but based on the parent/owner record. Context: Parent model: Project Child model: Activity Relationship: activities (Project->activities()) The issue is: canViewAny() on a RelationManager only receives the $user instance — but I need to decide access based on both the $user and the specific parent Project record. What I’d like to do: Check if the current user can view the Activities tab for a given Project canViewAny() doesn’t have access to the parent record Current state: ✅ Authorization works fine for default pages like Edit or View (via parent model Project Policy) ✅ Authorization works fine for view, edit, delete actions on the child model (via Child Model Activity Policy) ❌ But viewAny on the Activity model (to render the Activities tab on the Project resource) only accepts the $user instance — and I want to authorize it based on both the $user and the parent Project Any clean Filament-native way to handle this? Would appreciate suggestions or examples if you’ve tackled this before 👌
2 replies
FFilament
Created by H4L1M on 10/26/2024 in #❓┊help
Redirect to Profile On UsersRessource
Am trying to redirect the user to his own profile if he's trying to view or edit his own record on UsersRessource Am hiding his record with ModifyQueryUsing on $table on UsersRessource But a user can just edit the URL to access his resources (Not talking about Authorisation) I want to redirect to the Profile page if the user tries to view or edit his own User Model Any help ?
5 replies
FFilament
Created by H4L1M on 2/23/2024 in #❓┊help
Notification not working from Action Component
hello , I have this small action the notifications fail to lunch with no errors showed , the action works
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('triggerBanLogic')
->label('Ban')
->successNotificationTitle('The user has been successfully banned.')
->failureNotificationTitle('failed')
->closeModalByClickingAway(false)
->modalHeading('Ban User')
->icon('heroicon-o-no-symbol')
->color('danger')
->form([
Forms\Components\Group::make()
->schema([
Forms\Components\Radio::make('banType')
->label('')
->required()
->live()
->columnSpan(1)
->default('PermanentBan')
->options([
'PermanentBan' => 'Permanent Ban',
'TemporaryBan' => 'Temporary Ban',
]),
Forms\Components\DatePicker::make('expires_at')
->label('Ban until')
->required()
->displayFormat('d/m/Y')
->closeOnDateSelection()
->visible(fn (Get $get) => $get('banType') === 'TemporaryBan')
->minDate(now()->addDay()),
Forms\Components\TextInput::make('comment')
->label('Comment (Ban Reason)')
->required()
->columnSpanFull(),
])->columns(2)
])
->action(function (array $data, User $record) {
$data['banned_by'] = auth()->id();
$record->ban($data);
})
])->fullWidth()
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('triggerBanLogic')
->label('Ban')
->successNotificationTitle('The user has been successfully banned.')
->failureNotificationTitle('failed')
->closeModalByClickingAway(false)
->modalHeading('Ban User')
->icon('heroicon-o-no-symbol')
->color('danger')
->form([
Forms\Components\Group::make()
->schema([
Forms\Components\Radio::make('banType')
->label('')
->required()
->live()
->columnSpan(1)
->default('PermanentBan')
->options([
'PermanentBan' => 'Permanent Ban',
'TemporaryBan' => 'Temporary Ban',
]),
Forms\Components\DatePicker::make('expires_at')
->label('Ban until')
->required()
->displayFormat('d/m/Y')
->closeOnDateSelection()
->visible(fn (Get $get) => $get('banType') === 'TemporaryBan')
->minDate(now()->addDay()),
Forms\Components\TextInput::make('comment')
->label('Comment (Ban Reason)')
->required()
->columnSpanFull(),
])->columns(2)
])
->action(function (array $data, User $record) {
$data['banned_by'] = auth()->id();
$record->ban($data);
})
])->fullWidth()
4 replies
FFilament
Created by H4L1M on 2/22/2024 in #❓┊help
Save Action in a separate file
hello , can I save the actions in a separate file to use it in multiple places and avoid code duplication.. thank you ..
6 replies
FFilament
Created by H4L1M on 2/17/2024 in #❓┊help
Form Component Placeholder
hello, can placeholder's text colors be changed ? red and bold for example
Placeholder::make('User Status')
->content('Banned at : 02-17-2024 14:50 By Admin')
Placeholder::make('User Status')
->content('Banned at : 02-17-2024 14:50 By Admin')
5 replies