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