lundi 2 mai 2016

Laravel: Create a model and a dependent model simultaneously

Please help! I have a "Rate" model that holds information about the rates to charge. Each rate has a "Has Many" relationship to a "Rate Record" model. The Rate Record will be used to hold different rate amounts depending on the period (i.e. date range) in question, e.g. 01-JAN-2017 through 31-JAN-2017 will be $100.00, but 01-FEB-2017 through 28-FEB-2017 will be $120.00.

I am using a Multi Step Form (codecanyon-8591111-step-form-wizard) to create a Rate and ideally I want the following sequence: Step 1 - Create the basic information about a Rate (e.g. Code, description, etc.) Step 2 - Add Rate Records to the Rate Step 3 - Add more optional information about a Rate and Submit

My initial goal was to obtain all the information required on each step of the form using javascript validation for each form field, and once the form is submitted, my controller would create the Rate and associated Rate Records. I'm now unsure whether it would be easier/better to use an AJAX call after Step 1 to create the Rate and then somehow return the Rate ID and create the Rate Records in Step 2. So my first question is: Should I gather all the form data first and do the processing in my Controller or should I use AJAX calls in between?

I'm not a professional programmer, so my intended UI is beyond my capability at this stage, but I'm sure with some guidance I'll succeed.

My 2nd question is regarding the UI for Step 2. Does my create method on my Rate model have to call another create method on the Rate Record model using AJAX? What is your suggestion to tackle this scenario?

I'm sorry for the long Post and I hope I have provided enough information for you to understand my dilemma. I truly hope someone can help me! Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire