Пример #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function postIndex(Request $request, $id = null)
 {
     $id = Auth::user()->id;
     if ($request->has('user-id')) {
         $id = $request->get('user-id');
     }
     $product = Product::findOrFail($request->get('product'));
     $shoppingInterest = ShoppingInterest::firstOrNew(['user_id' => $id, 'product_id' => $product->id]);
     if (!$shoppingInterest->exists) {
         $shoppingInterest->amount = $request->get('amount');
         $shoppingInterest->unit = $request->get('unit');
         $shoppingInterest->save();
         $msg = 'Producto ' . $product->name . ' agreagdo';
         return response()->json(['msg' => $msg, 'product' => $product, 'shoppingInterest' => $shoppingInterest]);
     }
     return response()->json(['errors' => ['El producto ya fue agregado']]);
 }