Is it possible to manage different resources (models) on each Step inside a Wizard?
All models have some basic relationships between them and the state should be maintained between the steps.
I already figured out how to create a record after the first step using
afterValidation()
, but im struggling to pass the created model's id to the next step of the wizard in order to populate a Select
component with a ->relationship()
. Thanks in advace.5 Replies
Anyone, please?
@awcodes - when searching for 'wizard' here in discord i saw that you wrote to someone -
You’re trying to use the wizard as a multiple form instead of steps in a form so it going to require a more granular custom approach.
. Do you mind sharing any direction for that? Im struggling to manage a wizard with 3 steps where each step should handle a different form for a different resource, but still no success.
sorry if pinging you is considered rudeSorry, I’ve never done anything with the wizard like this. I’d have to see the code to even start to try to put it all together in my head.
sadly i can't share the whole repo so i'll paste some crucial pieces to understand the overall concept -
I have a resource called RfqResource and its create page with a wizard and these are the steps -
each of these
getBomFormSchema()
functions basically returns an array with the whole scheme, for example -
$this->getRfqFormSchema()
returns an array -
And on the assembly form there's a select field with a relationship to rfq -
(the reason i didn't use ->relationship('rfq','name')
because it tries to load this relationship on the rfq create page and obviously its wrong because rfq doesn't have a relationship called rfq as well)
I hoped I could somehow patch it by creating a real rfq on the first step -
And then pass this rfq's id to the next step like this -
But sadly it doesn't work and because both forms share some attributes with the same name (e.g. name
) then when moving to step 2 it basically derives the name of the rfq from step 1 because the wizard sees all these forms as one big form and not as separate ones.
Hope i was clear and provided enough infoStill not totally following the relationships here. Seems like the assembly relationship is backwards to me.
Ie, you’re assigning an rfq to assemblies instead of attaching assemblies to an rfq.
Assembly.php
-
Rfq.php
Basically, on the second step there should be some sort of a repeater for the assemblies while each of them should automatically derive the rfq's id that was created on the first step so eventually i won't have this field visible to the user since the rfq was already 'chosen' on the previous step -
Assembly.php
- getForm()
function -
Thanks again @awcodes for your time. It's not taken for granted!
Also, for some reason, im now missing the 'previous' button on the wizard. Only Next and Cancel are there
i managed to solve it with some public variables on the CreateRfq
itself which then I pass between each step and attaching this relationship on the step's afterValidation()
function, for example -
actually no.. its still not working. ugh.
on the last step it creates another new rfq and being redirected to its edit page with no assembly(ies) attached to it. how can i prevent the submit on the last step, or at least control it more granularly?