/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request, $orderID) { // create the new Order $inventory = new Inventory(); $order = Order::find($orderID); $bullet = Bullet::find($request->bullet_id); // Get the data $inventory->boxes = $request->boxes; $inventory->rounds_per_box = $request->rounds_per_box; $inventory->rounds = $request->rounds_per_box * $request->boxes; $inventory->cost_per_box = $request->cost_per_box; $inventory->cost = $request->cost_per_box * $request->boxes; $inventory->notes = $request->notes; // Make relationships $inventory->bullet()->associate($bullet); $inventory->order()->associate($order); // Update the totals $inventory->order->updateCost(); $inventory->order->updateRounds(); $inventory->order->save(); // Save the Order $inventory->save(); // Update inventory for all Bullets Bullet::updateInventory(); session()->flash('message', 'Inventory has been added'); session()->flash('message-type', 'success'); return redirect()->action('InventoryController@show', [$order->id, $inventory->id]); }