Single Form data to multiple tables.

Hi, my goal is to save single form data to multiple tables of database. When I have two models say "Product" and "Seller", and one form where seller creates a new product. If I keep product and seller models in relationship, and when I submit the form, does Laravel 5.4 automatically saves the respective data to both the tables? (Seller information to sellers table and product information to products table).

Luis Terrero replied 1 week ago

I believe you need to do that manually. Create the seller (and add its records to the DB) and use the seller id to add the products:

$seller = Seller::create($seller_info_array);

Use $seller->id as foreign_key to create the product or products you need add.

Product::create(['seller_id'=>$seller_id, of fields as array items..]);
Shiva Sheshendra replied 1 week ago

Thank you, Luis.

Sign in to participate in this thread!

We'd like to thank these amazing companies for supporting us