© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•4mo ago•
5 replies
Mike 🚀

Replicate action with custom after logic

I'm trying to add some additional logic to also sync relationships to the replicated model and not only the model itself. And due to a complex relationship setup I also need to do the replicate the model without events.

class ReplicateReportAction
{
    public static function make(): ReplicateAction
    {
        return ReplicateAction::make()
            ->mutateRecordDataUsing(fn (array $data): array => [...$data, 'name' => sprintf('%s copy', $data['name'])])
            ->modalDescription(fn () => __('actions.replicate_action.report_modal_description'))
            ->modalHeading(fn () => __('actions.replicate_action.report_modal_title'))
            ->using(fn (Report $record) => $record->replicate()->saveQuietly())
            ->after(function (Report $record, Report $replica) {
              // Custom logic that uses the replica id of the new model
            });
    }
}
class ReplicateReportAction
{
    public static function make(): ReplicateAction
    {
        return ReplicateAction::make()
            ->mutateRecordDataUsing(fn (array $data): array => [...$data, 'name' => sprintf('%s copy', $data['name'])])
            ->modalDescription(fn () => __('actions.replicate_action.report_modal_description'))
            ->modalHeading(fn () => __('actions.replicate_action.report_modal_title'))
            ->using(fn (Report $record) => $record->replicate()->saveQuietly())
            ->after(function (Report $record, Report $replica) {
              // Custom logic that uses the replica id of the new model
            });
    }
}


But when using this action
Argument #2 ($replica) must be of type App\Models\Report, null given
Argument #2 ($replica) must be of type App\Models\Report, null given
is thrown.
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Replicate action
FilamentFFilament / ❓┊help
2y ago
Replicate action with success redirect
FilamentFFilament / ❓┊help
3y ago
Custom logic after import completed
FilamentFFilament / ❓┊help
2y ago
Redirect after custom action
FilamentFFilament / ❓┊help
2y ago