/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, ProductsRequest $request) { //$this->validate($request, ['name' => 'required']); // Uncomment and modify if needed. $product = Products::findOrFail($id); $product->update($request->all()); return redirect('products'); }
/** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { // parent::boot($router); $router->bind('products', function ($value) { return Products::findOrFail($value); }); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function showCart() { $carts = Cart::content(); foreach ($carts as $cart) { $products = Products::findOrFail($cart->id); $quantityInStock = $products->quantityInStock - $cart->qty; DB::table('products')->where('id', '=', $cart->id)->update(['quantityInStock' => $quantityInStock]); } $total = Cart::total(); return view('users.pages.cart', compact('carts', 'total')); }
public function getViewProduct($id) { $product = Products::findOrFail($id); $brands = Brands::all(); $models = Models::all(); $productImages = DB::table('product_images')->where('in_product', $id)->get(); $randProducts = Products::orderBy(DB::raw('RAND()'))->take(3)->get(); $randImages = Images::all(); $price_text = ''; if ($product->price_count == 'yes') { $price_text = 'за брой'; } return view('pages.view-product')->with('product', $product)->with('brands', $brands)->with('models', $models)->with('productImages', $productImages)->with('randProducts', $randProducts)->with('randImages', $randImages)->with('price_text', $price_text); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function delete($id) { $productSizes = DB::table('productSize')->where('product_id', '=', $id)->select('id')->get(); foreach ($productSizes as $productSize) { DB::table('productSize')->whereIn('id', [$productSize->id])->delete(); } $images = DB::table('images')->where('product_id', '=', $id)->select('id')->get(); foreach ($images as $image) { DB::table('images')->whereIn('id', [$image->id])->delete(); } //deleteProduct $product = Products::findOrFail($id); $product->delete(); return Redirect::to('admin/product_list'); }
public function editProducts($id) { if (Auth::user()->email == '*****@*****.**') { $products = Products::findOrFail($id); $images = DB::select('select * from product_images where in_product = ?', [$id]); $productCategories = ProductCategories::all(); $subProductCategories = subProductCategories::all(); $brands = Brands::all(); $models = Models::all(); return view('admin.edit-products')->with('products', $products)->with('images', $images)->with('productCategories', $productCategories)->with('subProductCategories', $subProductCategories)->with('brands', $brands)->with('models', $models); } return redirect('/'); }
private function priceFilter($productname, $productname2) { $product_name = $productname . ' ' . $productname2; $products = \DB::table('products')->where('product_name', 'LIKE', '%' . $product_name . '%')->get(); if ($products) { foreach ($products as $product) { $updated = Products::findOrFail($product->id); $price_temp = $updated->product_price; $updated->product_price = 5555555; $updated->product_price_temp = $price_temp; $updated->updated_at = Carbon::now(); $updated->save(); } return false; } else { return true; } //return false means product exist and should only updated the price while //return true means product not exist and should add the whole product details to database }