当前位置: 首页>>代码示例>>PHP>>正文


PHP Product::whereIn方法代码示例

本文整理汇总了PHP中app\models\Product::whereIn方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::whereIn方法的具体用法?PHP Product::whereIn怎么用?PHP Product::whereIn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Product的用法示例。


在下文中一共展示了Product::whereIn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: show

 /**
  * Show Category.
  *
  * @return Response
  */
 public function show(Request $request, $slug)
 {
     $category = Category::where('slug', $slug)->first();
     if (!$category) {
         \App::abort(404);
     }
     // pagination
     $session_type = 'product';
     if (!$request->session()->has('order_by')) {
         $request->session()->put($session_type . '.order_by', 'created_at');
     }
     if (!$request->session()->has('order_dir')) {
         $request->session()->put($session_type . '.order_dir', 'desc');
     }
     if ($request->getorder_by) {
         $request->session()->put($session_type . '.order_by', $request->order_by);
     }
     if ($request->getorder_dir) {
         $request->session()->put($session_type . '.order_dir', $request->order_dir);
     }
     $orderby = $request->session()->get($session_type . '.order_by') == 'created_at' ? $request->session()->get($session_type . '.order_by') : $request->session()->get('language') . '.' . $request->session()->get($session_type . '.order_by');
     $limit = $request->session()->get('limit');
     $products = Product::whereIn('_id', $category->products)->orderBy($orderby, $request->session()->get($session_type . '.order_dir'))->paginate($limit);
     return view('themes/basic/categories/show', ['category' => $category, 'products' => $products]);
 }
开发者ID:kudosagency,项目名称:kudos-php,代码行数:30,代码来源:CategoriesController.php

示例2: getCategoryFilter

 public function getCategoryFilter($id)
 {
     $child_categories = [];
     foreach (Category::all() as $category) {
         if ($category->parent_id == $id) {
             $child_categories[] = $category->id;
         }
     }
     return view('products.index', ['products' => Product::whereIn('category_id', Category::find($id)->all_children())->get(), 'category' => Category::find($id), 'child_categories' => Category::whereIn('id', $child_categories)->get()]);
 }
开发者ID:venomir,项目名称:tc,代码行数:10,代码来源:ProductController.php

示例3: index

 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index($slug)
 {
     $explodeSlug = explode('-', $slug);
     $brandId = explode('.', end($explodeSlug))[0];
     if (!$brandId) {
         return false;
     }
     $obj = new Product();
     $AllparentID = Provider::where('parent_key', $brandId)->get()->toArray();
     $idPr = [];
     if ($AllparentID) {
         foreach ($AllparentID as $val) {
             array_push($idPr, $val['id']);
         }
         $res = Product::whereIn('provider_id', $idPr)->orderBy('id', 'desc');
     } else {
         $res = Product::where('provider_id', $brandId)->orderBy('id', 'desc');
     }
     $res = $this->paging($res, $this->req, false);
     $brandName = Provider::find($brandId);
     $data = ['title' => 'Nhãn hiệu', 'brand_name' => $brandName->name, 'product' => $res, 'total' => $this->total, 'total_page' => $this->total_page];
     return View::make('user/brand', $data);
 }
开发者ID:dao94,项目名称:game,代码行数:28,代码来源:BrandController.php

示例4: index

 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index($slug)
 {
     $explodeSlug = explode('-', $slug);
     $catId = explode('.', end($explodeSlug))[0];
     if (!$catId) {
         return false;
     }
     $catName = Category::find($catId);
     $obj = new Product();
     $AllparentID = Category::where('parent_key', $catId)->get()->toArray();
     $idPr = [];
     $res = [];
     if ($AllparentID) {
         foreach ($AllparentID as $val) {
             array_push($idPr, $val['id']);
         }
         $res = Product::whereIn('category_id', $idPr)->orderBy('id', 'desc');
     } else {
         $res = Product::where('category_id', $catId)->orderBy('id', 'desc');
     }
     $res = $this->paging($res, $this->req, false);
     $data = ['title' => 'Loại sản phẩm', 'cat_name' => $catName->name, 'product' => $res, 'total' => $this->total, 'total_page' => $this->total_page];
     return View::make('user/category', $data);
 }
开发者ID:dao94,项目名称:game,代码行数:29,代码来源:CategoryController.php

示例5: store

 public function store(Request $request)
 {
     try {
         DB::transaction(function () use($request) {
             $inputs = $request->input();
             $user = Auth::user();
             $time = time();
             $year = CommonHelper::get_current_financial_year();
             $order_quantity = 0;
             $deliver_quantity = 0;
             $products = Product::whereIn('id', array_keys($inputs['quantity']))->get()->toArray();
             //                dd($products);
             foreach ($inputs['quantity'] as $key => $value) {
                 if ($value > 0) {
                     $salesDelivery = SalesDeliveryDetail::firstOrNew(['sales_order_id' => $inputs['sales_order_id'], 'product_id' => $key]);
                     if ($salesDelivery->id) {
                         $salesDelivery->updated_by = $user->id;
                         $salesDelivery->updated_at = $time;
                         $d_quantity = $salesDelivery->delivered_quantity += $inputs['deliver_now'][$key];
                         $salesDelivery->last_delivered_quantity = $inputs['deliver_now'][$key];
                         $salesDelivery->save();
                     } else {
                         $salesDelivery->sales_order_id = $inputs['sales_order_id'];
                         $salesDelivery->created_by = $user->id;
                         $salesDelivery->created_at = $time;
                         $salesDelivery->status = 2;
                         //Partial Delivery
                         $salesDelivery->product_id = $key;
                         $salesDelivery->order_quantity = $value;
                         $d_quantity = $salesDelivery->delivered_quantity = $inputs['deliver_now'][$key];
                         $salesDelivery->last_delivered_quantity = $inputs['deliver_now'][$key];
                         $salesDelivery->save();
                     }
                     if ($d_quantity == $value) {
                         $salesDelivery->status = 4;
                         //product delivery completed
                         $salesDelivery->save();
                         $salesOrderItem = SalesOrderItem::firstOrNew(['sales_order_id' => $inputs['sales_order_id'], 'product_id' => $key]);
                         $salesOrderItem->status = 4;
                         // Sales item Delivery Completed
                         $salesOrderItem->save();
                     } else {
                         $salesDelivery->status = 2;
                         //Partial Delivery
                         $salesDelivery->save();
                         $salesOrderItem = SalesOrderItem::firstOrNew(['sales_order_id' => $inputs['sales_order_id'], 'product_id' => $key]);
                         $salesOrderItem->status = 2;
                         //Partial Delivery
                         $salesOrderItem->save();
                     }
                     $deliver_quantity += $d_quantity;
                     $order_quantity += $value;
                     $quantity_delivered = $inputs['deliver_now'][$key];
                     $stocks = Stock::where(['year' => $year, 'stock_type' => Config::get('common.balance_type_intermediate'), 'workspace_id' => $user->workspace_id, 'product_id' => $key])->first();
                     if ($inputs['unit_type'][$key] == 2) {
                         foreach ($products as $item) {
                             if ($item['id'] == $key) {
                                 $quantity_delivered = $quantity_delivered / $item['weight'] * $item['length'];
                                 break;
                             }
                         }
                     }
                     if ($stocks->quantity < $quantity_delivered) {
                         Session()->flash('warning_message', 'Insufficient stock.');
                         throw new \Exception();
                     }
                     $stocks->quantity -= $quantity_delivered;
                     $stocks->updated_by = $user->id;
                     $stocks->updated_at = $time;
                     $stocks->update();
                 }
                 if ($deliver_quantity == $order_quantity) {
                     $salesOrder = SalesOrder::find($inputs['sales_order_id']);
                     $salesOrder->status = 4;
                     // Sales Delivery Completed
                     $salesOrder->save();
                 } else {
                     $salesOrder = SalesOrder::find($inputs['sales_order_id']);
                     $salesOrder->status = 2;
                     //Partial Delivery
                     $salesOrder->save();
                 }
             }
         });
     } catch (\Exception $e) {
         Session()->flash('error_message', 'Products delivered failed.');
         return Redirect::back();
     }
     Session()->flash('flash_message', 'Products delivered successfully.');
     return redirect('salesDelivery');
 }
开发者ID:saj696,项目名称:pipe,代码行数:91,代码来源:SalesDeliveryController.php

示例6: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $feedid, $id)
 {
     if (Input::has('action')) {
         // Filter 作業
         switch ($request->input('action')) {
             case 'enable':
                 $enable_checked = Input::get('enable');
                 if (is_array($enable_checked)) {
                     //
                     $products = Product::onlyTrashed()->whereIn('id', $enable_checked)->get();
                     foreach ($products as $product) {
                         $product->restore();
                     }
                     // redirect
                     return Redirect::back()->with('message', 'Products Activate successfully');
                     //return redirect()->action('FeedProductController@index', [$id])->with('message', 'Error !: KEY 值重複 Feed_id:[ '.$id.' ]已有產品ID[ '.$item->product_id.' ]');
                 }
                 break;
             case 'disable':
                 $disable_checked = Input::get('disable');
                 if (is_array($disable_checked)) {
                     //
                     $products = Product::whereIn('id', $disable_checked)->get();
                     foreach ($products as $product) {
                         $product->delete();
                     }
                     // redirect
                     //Session::flash('message', 'Successfully deleted the platform!');
                     return Redirect::back()->with('message', 'Product Disable successfully');
                     //return redirect()->action('FeedProductController@index', [$id])->with('message', 'Error !: KEY 值重複 Feed_id:[ '.$id.' ]已有產品ID[ '.$item->product_id.' ]');
                 }
                 break;
         }
     } else {
         // 單一產品資料更新
         $validator = Validator::make($request->all(), ['name' => 'required|max:255', 'description' => 'required|max:3000', 'url' => 'required|max:300|url', 'image' => 'required|max:300|url', 'price' => 'required|integer', 'retail_price' => 'required|integer', 'category' => 'required|max:100', 'google_category' => 'required|max:100', 'brand' => 'required|max:20', 'condition' => "required|in:new,used,refurbished", 'availability' => 'required|in:in stock,out of stock,preorder']);
         if ($validator->fails()) {
             //return redirect('admin/feeds/'.$feedid.'/product/'.$id)
             return Redirect::route('admin.feeds.product.edit', array($feedid, $id))->withInput()->withErrors($validator);
         }
         try {
             $product = Product::where('feed_id', $feedid)->where('id', $id)->first();
             $product->name = $request->input('name');
             $product->description = $request->input('description');
             $product->url = $request->input('url');
             $product->image = $request->input('image');
             $product->price = $request->input('price');
             $product->retail_price = $request->input('retail_price');
             $product->category = $request->input('category');
             $product->google_category = $request->input('google_category');
             $product->brand = $request->input('brand');
             $product->condition = $request->input('condition');
             $product->availability = $request->input('availability');
             $product->save();
         } catch (Exception $e) {
         }
         return Redirect::route('admin.feeds.product.index', array($feedid))->with('message', 'Save - 產品內容更新完成!');
     }
 }
开发者ID:shihqi,项目名称:fms,代码行数:66,代码来源:FeedProductController.php

示例7: viewProducts

 /**
  * View Products of all Breeders
  *
  * @param  Request $request
  * @return View
  */
 public function viewProducts(Request $request)
 {
     // Check if search parameters are empty
     if (!$request->type && !$request->breed) {
         if ($request->sort && $request->sort != 'none') {
             $part = explode('-', $request->sort);
             $products = Product::whereIn('status', ['displayed', 'requested'])->where('quantity', '!=', 0)->orderBy($part[0], $part[1])->paginate(10);
         } else {
             $products = Product::whereIn('status', ['displayed', 'requested'])->where('quantity', '!=', 0)->orderBy('id', 'desc')->paginate(10);
         }
     } else {
         if ($request->type) {
             $products = Product::whereIn('status', ['displayed', 'requested'])->where('quantity', '!=', 0)->whereIn('type', explode(' ', $request->type));
         }
         if ($request->breed) {
             $breedIds = $this->getBreedIds($request->breed);
             if (!$request->type) {
                 $products = Product::whereIn('status', ['displayed', 'requested'])->where('quantity', '!=', 0)->whereIn('breed_id', $breedIds);
             } else {
                 $products = $products->whereIn('breed_id', $breedIds);
             }
         }
         if ($request->sort) {
             if ($request->sort != 'none') {
                 $part = explode('-', $request->sort);
                 $products = $products->orderBy($part[0], $part[1]);
             }
         }
         $products = $products->paginate(10);
     }
     $filters = $this->parseThenJoinFilters($request->type, $request->breed, $request->sort);
     $breedFilters = Breed::where('name', 'not like', '%+%')->where('name', 'not like', '')->orderBy('name', 'asc')->get();
     $urlFilters = ['type' => $request->type, 'breed' => $request->breed, 'sort' => $request->sort, 'page' => $products->currentPage()];
     foreach ($products as $product) {
         $product->img_path = '/images/product/' . Image::find($product->primary_img_id)->name;
         $product->type = ucfirst($product->type);
         $product->birthdate = $this->transformBirthdateSyntax($product->birthdate);
         $product->age = $this->computeAge($product->birthdate);
         $product->breed = $this->transformBreedSyntax(Breed::find($product->breed_id)->name);
         $product->breeder = Breeder::find($product->breeder_id)->users()->first()->name;
         $product->farm_province = FarmAddress::find($product->farm_from_id)->province;
     }
     return view('user.customer.viewProducts', compact('products', 'filters', 'breedFilters', 'urlFilters'));
 }
开发者ID:swinecommerceph,项目名称:swinecommerceph,代码行数:50,代码来源:ProductController.php


注:本文中的app\models\Product::whereIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。