public function save(Request $request) { $suppliers = $request->get('supplier_id'); $product = Product::create($request->all()); foreach ($suppliers as $supp) { SupplierProducts::create(['product_id' => $product->id, 'supplier_id' => $supp]); } $products = Product::all(); return view('pages.products', ['products' => $products]); }
public function save(Request $request) { // $product = Product::create($request->all()); // return $product; $suppliers = $request->get('supplier_id'); $product = Product::create($request->all()); foreach ($suppliers as $supp) { \App\Models\SupplierProducts::create(['product_id' => $product->id, 'supplier_id' => $supp]); } }