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


PHP Product::with方法代码示例

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


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

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $data = Product::with('category')->get();
     $data = DB::table('products')->leftJoin('categories', 'products.category_id', '=', 'categories.id')->leftJoin('photos', 'products.id', '=', 'photos.product_id')->select('products.*', 'categories.name as cname', 'photos.path as photo')->orderBy('cname')->paginate(self::perPage);
     //dd($data);
     return view('admin.product.index', compact('data'));
 }
开发者ID:shegun-babs,项目名称:dakrush,代码行数:12,代码来源:ProductController.php

示例2: index

 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $pro = new Product();
     $adSlotObj = new Adslot();
     $catObj = new Category();
     $brandObj = new Brand();
     /*getting all products for all slots(currently we have 7 slots)*/
     $adSlot_data = $adSlotObj->with(['products'])->get();
     /*t1-t7*/
     // dd($adSlot_data[4]['products'][0]);
     $category_temp_data = $catObj->orderBy('created_at')->take(10)->get();
     /*f1-f10*/
     $brand_data = $brandObj->with(['products'])->get();
     $category_data = [];
     foreach ($category_temp_data as $cat_id) {
         $cat_latest_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('photo_1');
         $cat_latest_product_id = $pro->where('category_id', '=', $cat_id['id'])->orderBy('created_at')->take(1)->pluck('id');
         $cat_random_product = $pro->where('category_id', '=', $cat_id['id'])->orderBy(DB::raw('RAND()'))->take(6)->get();
         $cat_brands = $pro->with(['brand'])->where('category_id', '=', $cat_id['id'])->take(5)->get();
         $cat_products_random_photos = [];
         foreach ($cat_random_product as $photo) {
             $cat_products_random_photos[] = $photo;
         }
         $category_data[] = ['color' => $cat_id['color'], 'floor' => $cat_id['floor'], 'name' => $cat_id['name'], 'desc' => $cat_id['description'], 'logo' => $cat_id['logo'], 'latest_photo_id' => $cat_latest_product_id, 'latest_photo' => $cat_latest_product, 'random_photos' => $cat_products_random_photos, 'brands' => $cat_brands];
     }
     return view('landing_page', compact(['adSlot_data', 'category_data']));
 }
开发者ID:khakanali,项目名称:OpenMAll,代码行数:32,代码来源:Landing.php

示例3: add

 public function add($id, $quantity, $color = false, $config = false)
 {
     $product = Product::with(['color', 'category'])->find($id);
     $this->items[$id]['product'] = $product;
     $this->items[$id]['quantity'] = $quantity;
     $this->items[$id]['color'] = $color;
     $this->items[$id]['configuration'] = $config;
 }
开发者ID:pechatny,项目名称:kolizej,代码行数:8,代码来源:Cart.php

示例4: index

 public function index(Request $request)
 {
     $q = $request->get('q');
     if ($q) {
     }
     $products = Product::with('brand')->with('stock')->with('unit')->where('name', 'LIKE', '%' . $q . '%')->orderBy('id', 'desc')->paginate(6);
     return $products;
 }
开发者ID:noodle-learns-programming,项目名称:laravel,代码行数:8,代码来源:ProductController.php

示例5: all

 public function all()
 {
     $products = Product::with('category')->get();
     if ($products->isEmpty()) {
         return $this->responseNotFound(['Products is empty']);
     }
     // Parse Result
     $result = $this->parseProducts($products);
     return $this->responseOk($result);
 }
开发者ID:restoko,项目名称:restoko-api,代码行数:10,代码来源:ProductsController.php

示例6: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $idxs = $this->getParameters()->getFilteringParameters()['ids'];
     $idxs ?: null;
     // avoid 'unused' warning
     /*echo "<pre>";
       print_r(Product::with('pricelists')->get());
       echo "</pre>";
       exit();*/
     return $this->getResponse(Product::with('pricelists')->get());
 }
开发者ID:guduchango,项目名称:limoncello,代码行数:16,代码来源:ProductsController.php

示例7: byIDWithBiddingDetails

 /**
  * @param $product_id
  * @return Product|Product[]|Collection|null
  */
 public function byIDWithBiddingDetails($item_id)
 {
     $base_relationships = array("bids");
     $relationships = $base_relationships;
     /** @var Collection $products */
     $products = Cache::remember('product' . implode("_", $product_id), CATALOG_CACHE_TIMEOUT, function () use($item_id, $base_relationships) {
         return Product::with($base_relationships)->whereIn('product_id', $item_id)->get();
     });
     foreach ($products as $product) {
         $product->prepare();
     }
     return $return_first ? $products->first() : $products;
 }
开发者ID:alexandrzavalii,项目名称:larabid,代码行数:17,代码来源:EloquentProductRepository.php

示例8: index

 public function index()
 {
     $categories = Input::get('cat');
     $per_page = 1000;
     //!IMPORTANT
     if ($categories != "") {
         if (Input::get("page") != "") {
             $page = (int) Input::get("page");
         } else {
             $page = 1;
         }
         if ($page == 1) {
             $page_calc = 0;
         } else {
             $page_calc = $page;
         }
         $cat_array = explode(",", $categories);
         $all_products = Product::join('product_cat', 'products.id', '=', 'product_cat.product_id')->whereIn('product_cat.cat_id', $cat_array)->get();
         $all_products_count = count($all_products);
         $last_page = ($all_products_count - $per_page) / $per_page + 1;
         $products_pivot = Product::join('product_cat', 'products.id', '=', 'product_cat.product_id')->whereIn('product_cat.cat_id', $cat_array)->skip($page_calc * $per_page - 1)->take($per_page)->get();
         $unique_products = [];
         foreach ($products_pivot as $item) {
             $found = false;
             foreach ($unique_products as $compare_item) {
                 if ($item->product_id == $compare_item->product_id) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $unique_products[] = $item;
             }
         }
         $products = [];
         foreach ($unique_products as $product) {
             $new_product = Product::find($product->product_id);
             $new_product->product_photos = $new_product->product_photos()->where("is_preview", "=", 1)->get();
             $products[] = $new_product;
         }
         $products = $this->buildPaginationResponse($products, $all_products_count, $per_page, $page, $last_page, $categories);
     } else {
         //            $products = Product::paginate($per_page);
         $products = Product::with("product_photos")->with(array('product_photos' => function ($query) {
             $query->where('is_preview', '=', 1);
         }));
         $products = $products->paginate($per_page);
     }
     return $products;
 }
开发者ID:leonstel,项目名称:czborduur,代码行数:50,代码来源:ProductController.php

示例9: detail

 public function detail($id)
 {
     $page = 'catalog';
     $title = Menu::where('key', $page)->value('name');
     $menuHtml = $this->menuHtml($page);
     $menuItems = Menu::all();
     $bottomMenuHtml = view('bottom', ['menuItems' => $menuItems])->render();
     $pageInfo = Page::where('key', $page)->first();
     $categories = Category::orderBy('sort', 'asc')->get();
     $product = Product::with(['category', 'color'])->find($id);
     $product->increment('views');
     $recommended = Product::with('category')->take(4)->get();
     $smallCart = $this->smallCart();
     $cartItem = $this->cartItem($product->id);
     $page = $product;
     $page->title = $product->name;
     return view('site.product', ['menuHtml' => $menuHtml, 'menuBottomHtml' => $bottomMenuHtml, 'title' => $title, 'page' => $page, 'product' => $product, 'categories' => $categories, 'recommended' => $recommended, 'count' => $smallCart['count'], 'sum' => $smallCart['sum'], 'currentItem' => $cartItem, 'currentProductCategory' => $product->category]);
 }
开发者ID:pechatny,项目名称:kolizej,代码行数:18,代码来源:CatalogController.php

示例10: boot

 /**
  * 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('book', function ($barcode) {
         return Product::where('barcode', $barcode)->firstOrFail();
     });
     $router->bind('unpublished', function ($barcode) {
         $product = Product::with(['organizations' => function ($query) {
             $query->find(Auth::user()->organization->id);
         }, 'is'])->where('barcode', $barcode)->firstOrFail();
         if ($product->organizations->first()->pivot->published == 0) {
             return $product;
         }
         return false;
     });
     $router->bind('user', function ($hash) {
         return User::where('hash', $hash)->first();
     });
 }
开发者ID:nicsmyrn,项目名称:library,代码行数:25,代码来源:RouteServiceProvider.php

示例11: index

 public function index($page = '')
 {
     //        $title = Menu::where('key', $page)->value('name');
     $categories = Category::orderBy('sort', 'asc')->get();
     $menuHtml = $this->menuHtml($page);
     if (session()->has('cart')) {
         $cartItems = session()->get('cart');
         $sum = $cartItems->sum();
         $count = count($cartItems->all());
     } else {
         $sum = 0;
         $count = 0;
     }
     $menuItems = Menu::all();
     $products = Product::with('category')->orderBy('views', 'desc')->take(8)->get();
     $bottomMenuHtml = view('bottom', ['menuItems' => $menuItems])->render();
     $page = Page::where('key', 'index')->first();
     return view('index', ['menuHtml' => $menuHtml, 'menuBottomHtml' => $bottomMenuHtml, 'categories' => $categories, 'count' => $count, 'sum' => $sum, 'products' => $products, 'indexFlag' => true, 'page' => $page]);
 }
开发者ID:pechatny,项目名称:kolizej,代码行数:19,代码来源:IndexController.php

示例12: edit

 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     $data['checkbox'] = Size::all();
     $data['product'] = Product::with('brands', 'size', 'category')->find($id);
     return view('product.edit', $data);
 }
开发者ID:raylight75,项目名称:cms,代码行数:12,代码来源:ArticlesController.php

示例13: showTrainCarProduct

 public function showTrainCarProduct($id, $depoId, ProductRepositoryInterface $productFromRepository, ProductCart $cart)
 {
     try {
         $product = Product::with(['price', 'price.stantion'])->where('id', $id)->first();
     } catch (ModelNotFoundException $e) {
         abort(404);
     }
     if (!$product) {
         abort(404);
     }
     if ($product->category_id) {
         $productParams = $productFromRepository->getProductProperties($id, true);
     } else {
         $productParams = $productFromRepository->getProductProperties($id, false);
     }
     $prices = $product->price;
     $pricesArr = [];
     foreach ($prices as $price) {
         if ($price->price > 0 && $price->amount > 0) {
             $pricesArr[$price->stantion[0]->train_road->tr_name][] = ['stantion_name' => $price->stantion[0]->stantion_name, 'stantion_id' => $price->stantion[0]->id, 'price_id' => $price->id, 'product_id' => $product->id, 'price' => $price->price, 'amount' => $price->amount];
         }
     }
     unset($prices);
     if (Auth::guest()) {
         $userID = 0;
     } else {
         $userID = Auth::user()->id;
     }
     $sumAndCount = $this->getGeneralViewOfCart($cart);
     return view('purchases.showTrainCarProduct', ['p' => 'purchases', 'depoId' => $depoId, 'productParams' => $productParams, 'prices' => $pricesArr, 'product' => $product, 'userID' => $userID, 'productsCount' => $sumAndCount['productsCount'], 'productsSum' => $sumAndCount['productsSum']]);
 }
开发者ID:kostik34,项目名称:trains.shop,代码行数:31,代码来源:PurchasesController.php

示例14: getDetail

 public function getDetail($id)
 {
     $mark = Mark::find($id);
     $products = Product::with('mark')->where('mark_id', '=', $id)->get();
     return view("products.detail")->with(array('mark' => $mark, 'products' => $products));
 }
开发者ID:Berenes,项目名称:INPQprueba,代码行数:6,代码来源:ProductController.php

示例15: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Product::with(['price'])->where('id', $id)->first();
     DB::transaction(function () use($product) {
         $product->price()->detach();
         foreach ($product->price as $price) {
             $price->delete();
         }
         $product->delete();
     });
     return back()->with('alert-success', 'Товар ' . $product->name . ' удален');
 }
开发者ID:kostik34,项目名称:trains.shop,代码行数:18,代码来源:ProductController.php


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