ReplicateAction with uniqid() as slug giving error
Hello,
I have extended my Page model and PageResource to add is_published and a few other custom fields. I have also added globalscope to not display pages with is_published = 0 for non authenticated users. My client asked me to add a ReplicateAction but since each page has a slug so I had to use beforeReplicaSaved to create uniqid() as slug and it creates the new page with all the details but when it redirects to edit page it gives me this error
"Undefined array key 21" whereas 21 is the auto-increment id.
Below is the code I am using in table actions.
Please let me know how do I fix this?
Thank you
ReplicateAction::make()
->beforeReplicaSaved(function (Model $replica): void {
$replica->slug = uniqid();
$replica->is_published = 0;
})
->successRedirectUrl(function (Model $replica) {
return route('filament.dashboard.resources.pages.edit', $replica->id);
}),
1 Reply
I just checked, I have to run php artisan optimize:clear to get it to work. I am not sure why do I have to run this command please ?
Anyone please ?
bump