F
Filament•23h ago
Kaesa Lyrih

Where to Inject a Custom Action in Filament EditPage After Policy and Validation Are Passed?

Hi everyone! 👋 I'm currently building a custom UpdateUserAction and would like to integrate it properly into a Filament EditRecord page. --- ✅ My Goal: I want to run a custom action (e.g., UpdateUserAction) only after: 1. Policy Authorization has passed (can:update on the model) 2. Validation has been successfully performed using the form schema 3. Data has been potentially transformed (if needed) --- 🤔 My Main Question: Which method inside the EditRecord or EditUser page is best for injecting a custom action after authorization and validation have passed? I want to avoid doing policy or validation inside the action itself — my goal is to delegate those responsibilities to Filament’s internal authorization and validation flow, and only call the action after that. For example:
protected function handleRecordUpdate(Model $record, array $data, UpdateUserAction $action): Model
{
// This seems like the correct place?
return $action->handle($record, $data); // Return User Model
}
protected function handleRecordUpdate(Model $record, array $data, UpdateUserAction $action): Model
{
// This seems like the correct place?
return $action->handle($record, $data); // Return User Model
}
Is handleRecordUpdate() guaranteed to run only after policy and validation have passed? If not, is there a more appropriate method to override? --- 🛠️ Context: I want to avoid calling FormRequest manually inside this method — I'd rather lean on Filament’s built-in validation and authorization mechanisms that already wrap around the EditPage lifecycle. --- 🙏 What I'm Looking For: * Confirmation that handleRecordUpdate() is the right place to inject my custom action. * If not, what would be the best method/hook to override? * Any example of delegating business logic into an action after Filament’s validation/policy pipeline. Thanks in advance for your help! I’d love to make this pattern as clean and idiomatic as possible with Filament. 🔧
1 Reply
charlie
charlie•7h ago
I think you can use handleRecordUpdate, and the authorization and validation is already done
protected function handleRecordUpdate(Model $record, array $data): Model
{
// transform your data
$data['your_data'] = 'something';

// do whatever you want
MyClass::callMe($data);

// update the record
$record->update($data);

// notify someone
Auth::user()->notify(...);

return $record;
}
protected function handleRecordUpdate(Model $record, array $data): Model
{
// transform your data
$data['your_data'] = 'something';

// do whatever you want
MyClass::callMe($data);

// update the record
$record->update($data);

// notify someone
Auth::user()->notify(...);

return $record;
}

Did you find this page helpful?