Redirect from a Create Page back to where it came from
I want to redirect from a Create Page which I triggered in the following way:
This
CreateAction
is inside my VacancyClassificationRelationManager
which lives on my VacancyResource
. I want to redirect back to my Vacancy Edit screen after I created a record.
How and where can I do this?22 Replies
Filament
Creating records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
Not sure which one you want. You mention CreatePage and Relation Manager? 🤔
Oh I see, you redirect to the CreatePage from the RM.
Yes, so I'm on an Edit Page, which of course is filtered. If I click 'Cancel' from the Create Page, I get back to the right page.
What redirect action is that?
It's the CancelAction
Yes, I understand 🙂 Just, how can I call that action from this redirectUrl() method?
Eh... this one
getRedirectUrl()
I don't think you can/should call actions directly.
Check the source code of the CancelAction if you want the code for the redirect.
Should be a simple
redirect()->back()
or similarOK. Thanks. Nothing seems to work anyways. If I create a new record and click 'Create', then the record is saved and I'm not being redirected but all form values are cleared and I can create a new record.
Have you tried the
after()
method on the CreateAction to redirect to where you want to go?
Something like that
Hmm.. not yet. I'll try that. Maybe I'm sticking with just showing the modal window. The only thing is that I actually want to save multiple entries based on the values of a CheckboxList inside the modal window. Is something like that also possible? So that I stop the default Save Action and manipulate the data myself?
manipulating the data in RMs is in the docs
But can I cancel the CreateAction and then do my own thing? I tried this:
you can override action() function instead to replace the default behaviour
check the internal CreateAction class, you can see how we built it
Owke... I need to dive into that 🙂 So basically you could override the CreateAction, get the Model data and do your own thing with that? Any example of how to override the action to begin with?
you just chain on
->action()
like you did ->before()
no need to create a new class. i was just telling you to look into CreateAction to see what the default configuration wasYes, that is clear. The following code works, but it feels a bit cumbersome. As if this could be done differently?
I have action with closure and ->form([...]) // with multiple entry fields, then in closure insert/update, whatever and in final return redirect
in the end redirect and yes..
Well, the modal closes automatically, so no need for a redirect?
I redirect for edit new record
$livewire->ownerRecord
is the vacancy, so why find() it again?
then you can use $vacancy->classifications()->create(['vacancy_type_classification_id' => $id])
to create and save at once
Thanks. That is indeed a better way.
you can probably improve it using createMany()