/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $item = $request->all(); $item['user_id'] = Auth::user()->id; if (Entry::create($item)) { Product::find($item['product_id'])->increment('quantity', $item['quantity']); /*********************************************************************************** * Product::find($item['products_id'])->increment('quantity',$item['quantity']); * ------------------------------------------------------------------------------------- * Selecionando coluna especifica para update da mesma colando acima realiza o mesmo procedimento * * $quantity = Product::where('id',$item['products_id'])->pluck('quantity'); * $quantity += $item['quantity']; * Product::where('id',$item['products_id'])->update(['quantity'=> $quantity]); * $product['quantity'] += $item['quantity']; * $product->save(); */ Session::flash('message', 'Item inserido com sucesso'); return Redirect::to('entries'); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { Product::destroy($id); Session::flash('message', 'Produto excluido com sucesso'); return Redirect::to('/products'); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { return view('outputs.edit', ['product' => Product::findOrFail($id)]); }