简体   繁体   中英

Upload in Laravel inside another Controller

I'm working with two tables

A line table has:

  • Id
  • Name
  • Description

A Product table has:

  • Id
  • Name
  • Description
  • Line ID

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

产品模态形式

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM