Back

How attach after save another model


Hi friends, help me please, how I can do for save InventorEntry model and get the id for attach a product on a manytomany relationship, thanks!

public function store(Request $request)
{
    $inventory_entry=InventoryEntry::create([
        'quantity_entry'=>$request->get('quantity_entry'),
        'user_id'=>Auth::user()->id,
        ]);
    $getProduct=\Tlc\Product::where('id','=',$request->product_id)->first();
    $product=\Tlc\Product::find($getProduct->id);
    $product->inventoryentries->attach($getProduct->id);
    return redirect('inventory_entry.index')->with('message', 'store');
}

Sign in to participate in this thread!



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