Get data in ->after() on a custom action
I have the following code. I would like to get the newly created record to use as a redirect in the ->after() function. If any one could help I would appreciate it. Also if I am doing this a long way please let me know.
13 Replies
->after(function (Model $record) {})
For Record this is on the List page with a custom header action. Doesn't look like its passed the created object across.
Weird, you can notification and redirect inside action itself if
after()
not working, like this
And one thing, here in Model
Did you use Model (use Illuminate\Database\Eloquent\Model;) or your Day model? I use actual Model and I don't have any errorI did have it as Day but I just tried Model and have the same error.
I did have this to begin with but as I am using the new ->unsavedChangesAlerts() on v3.2 it is popping up saying I have unsaved before redirecting which ruins the flow.
If you try like this, then what did you get?
The error in here seems like you passed wrong data in $record
(return redirect() -> route('view', ['record' => 'wrong']);)
and I used use Illuminate\Database\Eloquent\Model;
Yeah, understood.. this is custom data, I don't know how to pass the record but get the last record from after like this
No problem, thank you for the assit and the code snippet. Much appreciated
One thing, I have this in my code hope this works for you too, try
$this->record
inside after()
without importing (Model $record)
oh well, was worth a shot
are you doing this inside the ListRecord page? in the protected function getHeaderActions() ?
Yes inside list, now i dont know any other solution
strange, I wonder why it works okay for you and not myself. Its not the end of the world though, the code I have works. thanks again
😆 it's because the actions perform different, maybe