LuisG's avatar

inserting related models

I have two models in one to many relationship. In edit.blade.php of model one side, i need to do a crud of model side many. How do that?. I have do the index of model side many, but how show the form of create model side many? Where redirect when touch save button of this create? what put in the controller? I have to do that with javascript? Sorry my english

1 like
3 replies
vincent15000's avatar

Please use ChatGPT to translate your post from your mother tongue.

LuisG's avatar

Thanks for the quick response. I have two models: rc_RendicionDeCuentas and rc_OPIs. The relationship is one-to-many from rc_RendicionDeCuentas to rc_OPIs. My questions are: a) How to display the rc_OPIs form in edit.blade.php when the create rc_OPIs button is selected? b) In the rc_OPIs controller: in store, I first store rc_RendicionDeCuentas and then rc_OPIs, and where do I send the view? /* Model: rc_RendicionDeCuentas*/

1 like
vincent15000's avatar

That's not clear, I don't understand all what you are talking about.

For a one to many relationship, you have 2 options :

Option 1 - use a form to create only the rc_RendicionDeCuentas without the rc_OPIs, then show the rc_RendicionDeCuentas model and create the different rc_OPIs one per one (both models are created from 2 distinct forms)

Option 2 - use a form to create the rc_RendicionDeCuentas and the rc_OPIs at the same time in the same form, to do that you need to add the fields dynamically for rc_OPIs (via AlpineJS, VueJS, Livewire, ... or whatever technology like these ones)

For option 2, you would have the fields for the rc_RendicionDeCuentas model and in the same form a + button to add fields dynamically for the rc_OPIs models.

Please or to participate in this conversation.