Reputation: 2554
I'm working with two tables
A line table has:
A Product table has:
So, I have a Line view to insert the name and description, also, bellow this form, I have a button to add a new product.
This button opens a modal with another form (name, description, file input) for create a product.
Therefore, I'm confuse.
1 - Do I have to create the product, but without any Line ID?
2 - How can I send the product data to Line view after create the new product? (I have to use Ajax)
3 - Do I have to save the line data with all products together?
Line Form
Product Modal Form
Upvotes: 0
Views: 234
Reputation: 718
1 - Do I have to create the product, but without any Line ID?
Answer: Does the product need to have a Line
before you can add it? Usually the answer to this is, have the user create the line first and then the product. So for example, Macbook Pro
as a product. The user will first need to create a line called Apple
, then he can create the product and choose Apple.
2 - How can I send the product data to Line view after create the new product? (I have to use Ajax)
Answer: You can do everything within the same controller. Just fetch the product/line data within the controller, and send it all the the view. If you're looking to do it through Ajax, just create a controller and route for example: /api/products/all
which returns a list of all the products. Or you can also do: /api/products/store
to store products, and within the controller return the product that was saved back to ajax call.
3 - Do I have to save the line data with all products together?
Answer: No, usually you save the line data first, then the product data follows.
Upvotes: 1