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


PHP Product::findOrFail方法代码示例

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


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

示例1: doSearch

 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);
 }
开发者ID:m-gamal,项目名称:crm,代码行数:25,代码来源:SaleController.php

示例2: update

 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);
 }
开发者ID:Peelz,项目名称:bait,代码行数:28,代码来源:ProductController.php

示例3: update

 /**
  * 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');
 }
开发者ID:pavhov93,项目名称:laravel_dashboard,代码行数:14,代码来源:ProductsController.php

示例4: show

 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);
 }
开发者ID:sandywalker,项目名称:xiehouxing,代码行数:29,代码来源:ActivityController.php

示例5: show

 public function show($id)
 {
     $product = Product::findOrFail($id);
     //return $id;
     //dd($product);
     return view('pages.detail', compact('product'));
 }
开发者ID:AMFIRNAS,项目名称:PaintBuddy,代码行数:7,代码来源:PagesController.php

示例6: destroy

 public function destroy($id, Request $request)
 {
     $product = Product::findOrFail($id);
     $product->delete();
     $request->session()->flash('message', 'Medicine successfuly deleted');
     return redirect()->back();
 }
开发者ID:jmramos02,项目名称:store-locator-api,代码行数:7,代码来源:ProductController.php

示例7: getEdit

 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'));
 }
开发者ID:nguyentandat43,项目名称:booksonline,代码行数:7,代码来源:ProductContoller.php

示例8: edit

 /**
  * 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'));
 }
开发者ID:Antoine07,项目名称:appStarwars,代码行数:13,代码来源:ProductController.php

示例9: showProduct

 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'));
 }
开发者ID:patlegris,项目名称:appStarWars,代码行数:7,代码来源:FrontController.php

示例10: manage

 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'];
 }
开发者ID:ikliko,项目名称:Maxverf,代码行数:31,代码来源:ProductSize.php

示例11: update

 /**
  * 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.');
 }
开发者ID:laraviet,项目名称:catalog,代码行数:14,代码来源:ProductController.php

示例12: getPlace

 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]);
 }
开发者ID:edgars-supe,项目名称:wt2-hw2,代码行数:25,代码来源:OrderController.php

示例13: showProduct

 /**
  * 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'));
 }
开发者ID:yinilauriot,项目名称:StarWars,代码行数:13,代码来源:FrontController.php

示例14: app

 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);
 }
开发者ID:unionbt,项目名称:hanpaimall,代码行数:8,代码来源:ProductAttrController.php

示例15: show

 /**
  * 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'));
 }
开发者ID:sgh1986915,项目名称:laravel-eyerideonline,代码行数:14,代码来源:ProductController.php


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