public function getVendorProducts(Request $request) { $validator = Validator::make($request->all(), ['vendor_id' => 'required|exists:users,id']); if ($validator->fails()) { return response()->json(['success' => false, 'error_code' => ErrorConstants::CUSTOMER_GET_VENDOR_PRODUCTS_VALIDATOR_FAILS, 'error_message' => $validator->errors()->getMessages()]); } $vendor_id = $request->input('vendor_id'); $vendor = User::find($vendor_id); $products = Product::where('user_id', $vendor_id)->with('user')->with('productUnit'); return response()->json(['success' => true, 'data' => ['vendor' => $vendor, 'products' => $products->get()]]); }
public function showHome() { //gets latest post $news = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 1)->orderBy('updated_at', 'desc')->first(); $job = Post::where('is_published', 1)->where('is_active', 1)->where('post_type', 2)->orderBy('updated_at', 'desc')->first(); $product = Product::where('is_active', 1)->orderby('updated_at', 'desc')->first(); $project = Project::where('is_public', 1)->where('is_active', 1)->orderBy('updated_at', 'desc')->first(); $newsContent = htmlspecialchars_decode($news->content, ENT_NOQUOTES); $news->content = $newsContent; //dd($news); return view('pages.home', ['news' => $news, 'job' => $job, 'product' => $product, 'project' => $project]); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { try { $this->validate($request, ['product_name' => 'required|max:255|min:3', 'product_desc' => 'required|min:10|max:500', 'price' => 'required|numeric']); //dd($id); $is_active = $request->input('is_active') ? true : false; $productobj = new Product(); $productobj->where('id', $id)->update(['product_name' => $request->input('product_name'), 'product_desc' => $request->input('product_desc'), 'category_id' => $request->input('product_category'), 'product_code' => $request->input('productcateg_code'), 'size' => $request->input('size'), 'price' => $request->input('price'), 'is_active' => $is_active]); //update attachment images if ($request->has('img')) { foreach ($request->input('img') as $img) { //unserialize image value $imgVal = unserialize($img); if ($imgVal[1]) { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['attachment_id' => $id]); } else { $fileObj = new Files(); $fileObj->where('id', $imgVal[0])->update(['is_active' => false]); } } } return Redirect::to("/back/product/edit/{$id}")->with('message', $request->input('product_name') . ' was successfully updated'); } catch (Exception $e) { return Redirect::to("/back/product/edit/{$id}")->with('message', 'Oops! Something went wrong. Please try again later'); } }
function getByCategory($cate) { return Product::where('type', $cate)->get(); }