public function doSearch(SalesSearchRequest $request) { $searchResult = []; $from = $request->date_from; $to = $request->date_to; $products = $request->products; $MRs = $request->mrs; $allSearchedReport = Report::select('sold_products')->where('date', '>=', $from)->where('date', '<=', $to)->whereIn('mr_id', $MRs)->where('sold_products', '<>', 'NULL')->get(); foreach ($allSearchedReport as $singleReport) { foreach (json_decode($singleReport) as $soldProducts) { foreach (json_decode($soldProducts) as $singleProduct => $quantity) { $productName = Product::findOrFail($singleProduct)->name; if (in_array($singleProduct, $products)) { if (isset($searchResult[$productName])) { $searchResult[$productName] += $quantity; } else { $searchResult[$productName] = $quantity; } } } } } $dataView = ['searchResult' => $searchResult]; return view('am.search.sales.result', $dataView); }
public function update(Request $request, $id) { $product = Product::findOrFail($id); $product->name = $request->name; $product->description = $request->description; $product->sku = $request->sku; $product->price = $request->price; $product->special_price = $request->special_price; if ($request->category != null) { $product->category = $request->category; } $product->is_active = $request->is_active; $product->quanlity = $request->quanlity; if ($request->images != null) { $path = "/catalog/img/product/" . $product->id . "/"; foreach ($request->images as $img) { $img_product = new ProductImage(); $img_product->pro_id = $product->id; $imgName = $img->getClientOriginalName(); $img_product->pro_id = $product->id; $img_product->path = $path . $imgName; $img->move(public_path($path), $imgName); $img_product->save(); } } $product->save(); return redirect('admin/product/' . $id); }
/** * Update the specified resource in storage. * * @param int $id * * @return Response */ public function update($id, Request $request) { $product = Product::findOrFail($id); $product->update($request->all()); Session::flash('flash_message', 'Product updated!'); return redirect('web/products'); }
public function show($id) { $activity = Activity::findOrFail($id); $activity->load('members.user'); $activity->load('comments.user'); $user = []; $joined = false; $member = null; if (Auth::check()) { $user = User::findOrFail(Auth::user()->id); $joined = ActivityMember::isJoined($id, $user->id); $member = ActivityMember::where('activity_id', $id)->where('user_id', $user->id)->first(); if ($member != null) { $member->load('activity'); } } $photos = Product::findOrFail($activity->product_id)->photos; $members = $activity->members; $activities = Activity::where('istop', 1)->orderBy('order_number')->take(5)->get(); $activities = $activities->filter(function ($item) use($activity) { return $item->id != $activity->id; }); $models = compact('activity', 'members', 'photos', 'joined', 'activities'); if (Auth::check()) { $models['user'] = $user; $models['member'] = $member; } return view('activity.show', $models); }
public function show($id) { $product = Product::findOrFail($id); //return $id; //dd($product); return view('pages.detail', compact('product')); }
public function destroy($id, Request $request) { $product = Product::findOrFail($id); $product->delete(); $request->session()->flash('message', 'Medicine successfuly deleted'); return redirect()->back(); }
public function getEdit($id) { $category = Category::select('id', 'name', 'prarent_id')->get()->toArray(); $product = Product::findOrFail($id); $product_img = Product::findOrFail($id)->pimages()->get()->toArray(); return view('backend.product.edit', compact('category', 'product', 'product_img')); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $product = Product::findOrFail($id); $tags = Tag::lists('name', 'id'); $categories = Category::lists('title', 'id'); return view('admin.product.edit', compact('product', 'tags', 'categories')); }
public function showProduct($id, $slug = '') { $product = Product::findOrFail($id); $title = " Page product:{$product->name}"; $quantities = range(1, $product->quantity); return view('front.show', compact('product', 'title', 'quantities')); }
public static function manage($data, $id = null) { if ($id) { $data['id'] = $id; } $rules = $id ? self::rules(true) : self::rules(); $messages = $id ? self::messages(true) : self::messages(); $validator = Validator::make($data, $rules, $messages); if ($validator->fails()) { return ['error' => ['type' => 'validation', 'messages' => $validator]]; } try { $size = $id ? ProductSize::find($id) : new ProductSize(); $size->size = $data['size']; $size->price = $data['price']; $size->product_id = $data['product_id']; $size->price = $data['price']; $size->promo_type = $data['promo_type']; $size->promo = $data['promo']; $promo = $data['promo'] + 0; if ($promo) { $product = Product::findOrFail($data['product_id']); $product->setOnPromo(); var_dump($product); } $size->save(); } catch (\Exception $ex) { return ['error' => ['type' => 'saving', 'messages' => $ex->getMessage(), 'trace' => $ex->getTraceAsString()]]; } return ['error' => ['type' => 'no'], 'success' => 'You successfully added size']; }
/** * Update the specified resource in storage. * * @param int $id * @param Request $request * @return Response */ public function update(ProductRequest $request, $id) { $inputData = $request->all(); $product = Product::findOrFail($id); $product->updateProduct($inputData); return redirect()->action('Admin\\ProductController@index')->with('message', 'Item updated successfully.'); }
public function getPlace(Request $request) { $total = 0.0; //Shamelessly copied from getCart, because why not? $display_result = array(); $current_cart = $request->session()->get('cart', array()); if (count($current_cart) == 0) { //Just making sure that it's not possible to place an empty order return redirect('order/cart'); } foreach ($current_cart as $product_id => $count) { if ($count > 0) { $cart_item = array(); $product = Product::findOrFail($product_id); $cart_item['id'] = $product->id; $cart_item['name'] = $product->name; $cart_item['price'] = $product->price; $cart_item['count'] = $count; $cart_item['total'] = $product->price * $count; $total += $cart_item['total']; $display_result[] = $cart_item; } } return view('order_place', ['total' => $total, 'items' => $display_result]); }
/** * Display the details and order form of a product * * @param $id * @param string $slug */ public function showProduct($id, $slug = '') { $bests = Product::orderBy('score', 'desc')->orderBy('price', 'desc')->take(4)->get(); $product = Product::findOrFail($id); $title = "Product {$product->name}"; return view('front.prod', compact('product', 'bests', 'title', 'customer_id')); }
function __construct() { parent::__construct(); $this->_pid = app('request')->get('pid'); isset($this->_pid) && session(['pid' => $this->_pid]); !isset($this->_pid) && ($this->_pid = session('pid')); $this->_product = Product::findOrFail($this->_pid); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $product = Product::findOrFail($id); if ($product->category == 'Accessories') { return view('products.accessories', compact('product')); } return view('products.general', compact('product')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $p = Product::findOrFail($id); $this->validate($request, ['code' => 'required|min:3|max:5', 'name' => 'required']); $p->fill($request->all())->save(); Session::flash('flash_message', "Product berhasil disimpan"); return redirect()->route('product.index'); }
/** * 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 ($id) { return \App\Product::findOrFail($id); }); }
public function show($id) { $product = Product::findOrFail($id); // if (is_null($product)) { // abort(404); // } return view('products.show', compact('product')); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $product_size = ProductSize::findOrFail($id); $product = Product::findOrFail($product_size->product_id); $category = $product->category; $products = Product::where('category_id', '=', $category->id)->lists('name', 'id'); return view('product_size.edit', compact('category', 'products', 'product', 'product_size')); }
public function removeProduct(Request $request) { $order = Auth::user()->cart(); $product_id = $request->input('product_id'); $product = Product::findOrFail($product_id); $order->products()->detach($product->id); return redirect()->route('cart'); }
/** * @param StorePhotoRequest $request * @return \Illuminate\Http\JsonResponse */ public function storeNewImages(StorePhotoRequest $request) { $productId = $request->input('productId'); $product = Product::findOrFail($productId); $path = $request->file('photo'); $product->addMedia($path)->toCollection('images'); return response()->json(['success' => true, 'Message' => 'Your images were successfully uploaded']); }
/** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $extra = Extra::findOrFail($id); $product_size = ProductSize::findOrFail($extra->product_size_id); $product = Product::findOrFail($product_size->product_id); $category = Category::findOrFail($product->category_id); $product_sizes = ProductSize::where('product_id', '=', $product->id)->lists('size', 'id'); return view('extra.edit', compact('product_size', 'product', 'category', 'product_sizes', 'extra')); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if ($request->ajax()) { $product = Product::findOrFail($id); $product->update($request->all()); $message = 'El producto fue actualizado satisfactoriamente'; return response()->json(['message' => $message, 'url' => '/']); } }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(Request $request, $id) { $this->validate($request, ['name' => 'required', 'units' => 'required']); $product = Product::findOrFail($id); $product->status = $request->has('status') ? true : false; $product->update($request->all()); message()->success('Successfully updated Product'); return ['location' => action('ProductsController@index')]; }
public function update(Request $request, $id) { $this->validate($request, ['name' => 'required|min:2']); // Find the product we are editing $product = Product::findOrFail($id); $product->name = $request->name; $product->save(); return redirect('products/' . $id); }
public function index() { $user = Auth::user(); $arProducts = []; foreach ($user->bags->where('inBag', 0) as $key => $product) { $arProducts[$key] = Product::findOrFail($product->productId); } return view('heartBag.index')->with('products', $arProducts); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store($productId, Request $request) { $product = Product::findOrFail($productId); $product->descriptions()->save(new Description(['body' => $request->input('body')])); return $product->descriptions; // return Description::create([ // 'product_id' => $productId, // ]); }
public function update(Request $request, $id) { $this->validate($request, ['name' => 'required|min:2|max:50']); //find product being edited $product = Product::findOrFail($id); $product->name = $request->name; $product->save(); return redirect('products/' . $id); }
public static function fromProduct($productId, $startTime) { $product = Product::findOrFail($productId); $activity = Activity::create($product->toArray()); $activity->product_id = $product->id; $activity->start_date = Carbon::createFromFormat('Y-m-d', $startTime); $activity->thumb = $product->thumb; $activity->banner = $product->banner; $activity->save(); }
public function doDelete($id) { $product = Product::findOrFail($id); try { $product->delete(); return redirect()->back()->with('message', 'Product has been deleted successfully !'); } catch (ParseException $ex) { echo 'Failed to delete this product , with error message: ' . $ex->getMessage(); } }