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


PHP Product::findOrFail方法代码示例

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


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

示例1: createTransfer

 /**
  *
  * Создает новый трансфер с указанным списком товаров, но не проводит его
  * Если указанно, то создает резерв товара
  *
  * @param ProductQtyCollection $collection
  * @param Warehouse $source
  * @param Warehouse $target
  * @param boolean $reserve //зарезервировать товары?
  * @return StockTransfer
  */
 public function createTransfer(ProductQtyCollection $collection, Warehouse $source, Warehouse $target, $reserve = false)
 {
     if ($source->organization()->id != $target->organization()->id) {
         throw new StockException('Для перемещения между организациями, используйте метод StockRepository::createOrganisationsTransfer');
     }
     $transfer = new StockTransfer();
     $organization = $source->organization();
     $transfer->sourceOrganization()->associate($organization);
     $transfer->targetOrganization()->associate($organization);
     $transfer->sourceWarehouse()->associate($source);
     $transfer->targetWarehouse()->associate($target);
     $transfer->save();
     foreach ($collection as $row) {
         $productId = $row['id'];
         $qty = $row['qty'];
         $product = Product::findOrFail($productId);
         $stock = $this->stockRepository->findStockByProductAndWarehouse($product, $source);
         if (empty($stock)) {
             throw new StockNotFound();
         }
         $item = new StockTransferItem();
         $item->product()->associate($product);
         $item->stock()->associate($stock);
         $item->setQty($qty);
         $item->save();
     }
     if ($reserve === true) {
         $transfer->is_reserved = true;
         $rep = new ReserveRepository();
         $rep->createByDocument($transfer);
     }
     return $transfer;
 }
开发者ID:ElMiKu,项目名称:AQAL,代码行数:44,代码来源:TransferRepository.php

示例2: getProductMedia

 /**
  * Media uploads for a product.
  */
 public function getProductMedia($id)
 {
     // Get the product.
     $product = Product::findOrFail($id);
     // Render the view.
     return View::make('admin.products.media', ['product' => $product]);
 }
开发者ID:Fash1,项目名称:Fash1,代码行数:10,代码来源:AdminController.php

示例3: update

 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $product->update($data);
     return Redirect::route('products.index');
 }
开发者ID:NocturnalWare,项目名称:managedotband,代码行数:16,代码来源:ProductsController.php

示例4: delete

 public function delete($id)
 {
     try {
         $product = Product::findOrFail($id);
         $product->delete(['id']);
         return Redirect::back()->with('error', false)->with('msg', 'Producto removido exitosamente.')->with('class', 'warning');
     } catch (Exception $exc) {
         echo $exc->getMessage() . " " . $exc->getLine();
         return Redirect::back()->with('error', true)->with('msg', '¡Algo salió mal! Contacte con administrador')->with('class', 'danger');
     }
 }
开发者ID:prianticonsulting,项目名称:Habitaria,代码行数:11,代码来源:ProductController.php

示例5: store

 /**
  * Store a newly created resource in storage.
  * POST /carts
  *
  * @return Response
  */
 public function store()
 {
     if ($id = Input::get('id')) {
         $product = Product::findOrFail((int) $id);
         $item = array('id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => 1);
         Cart::insert($item);
         return Cart::totalItems(true);
     } else {
         return false;
     }
 }
开发者ID:VerticalHorizon,项目名称:Bumagi,代码行数:17,代码来源:CartController.php

示例6: postAdd

 public function postAdd()
 {
     if (Request::ajax()) {
         $productId = Input::get('productId');
         $product = Product::findOrFail($productId);
         $name = Input::get('name');
         $price = Input::get('price');
         $link = 'product/' . $product->link;
         Cart::add(['id' => $productId, 'name' => $name, 'qty' => 1, 'price' => $price, 'options' => ['link' => $link]]);
         return Response::json(array('productId' => $productId, 'name' => $name, 'price' => $price, 'link' => $product->link));
     }
 }
开发者ID:Rotron,项目名称:shop,代码行数:12,代码来源:CartController.php

示例7: getDelete

 public function getDelete($id)
 {
     $delete = Product::findOrFail($id);
     if (!$delete) {
         return Redirect::to('product');
     }
     $delete->delete();
     if (!$delete->delete()) {
         return Redirect::to('product')->with(['message' => 'true', 'title' => 'Tebrikler!', 'text' => 'Ürün kaydı başarıyla silindi.', 'type' => 'success']);
     } else {
         return Redirect::to('product')->with(['message' => 'true', 'title' => 'Hata!', 'text' => 'Ürün kaydı silinemedi! Lütfen daha sonra tekrar deneyiniz.', 'type' => 'error']);
     }
 }
开发者ID:osmanyilmazco,项目名称:ordermanager,代码行数:13,代码来源:ProductsController.php

示例8: update

 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make($data = Input::all(), Product::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $vendor = Vendor::find(Input::get('vendor_id'));
     $product->vendor()->associate($vendor);
     $product->name = Input::get('name');
     $product->description = Input::get('description');
     $product->price = Input::get('price');
     $product->status = 'active';
     $product->update();
     return Redirect::route('products.index');
 }
开发者ID:kenkode,项目名称:xaraerp,代码行数:22,代码来源:ProductsController.php

示例9: show

 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $product = $this->product->findOrFail($id);
     return View::make('products.show', compact('product'));
 }
开发者ID:maldewar,项目名称:jidou,代码行数:11,代码来源:ProductsController.php

示例10: deleteDestroyproduct

 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  * @return Response
  */
 public function deleteDestroyproduct($id)
 {
     $product = Product::findOrFail($id);
     $product->delete();
     $bank = $product->bank;
     flash()->success('Producto eliminado con éxito.');
     return view('admin.showproduct', compact('bank'));
 }
开发者ID:EstebanJesus,项目名称:bancopedagogico-v2,代码行数:14,代码来源:ProductsTraits.php

示例11: update

 /**
  * Update the specified product in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $product = Product::findOrFail($id);
     $validator = Validator::make(Input::all(), Product::$rules);
     if ($validator->passes()) {
         $product->update(array('id' => $id, 'unit_id' => Input::get('unit_id'), 'name' => Input::get('name'), 'price' => Input::get('price'), 'cost' => Input::get('cost'), 'description' => Input::get('description'), 'created_at' => Carbon\Carbon::today(), 'producer' => Input::get('producer'), 'country' => Input::get('country')));
         return Response::json(array('success' => true, 'message' => array('type' => 'success', 'msg' => 'Cập nhật hàng hóa thành công!')));
     } else {
         return Response::json(array('success' => false, 'errors' => $validator->errors()));
     }
 }
开发者ID:jimmyhien,项目名称:dailyhuuhoc,代码行数:17,代码来源:ProductsController.php

示例12: destroy

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $product = Product::findOrFail($id);
     $product->delete();
     return Redirect::route('product.index');
     // redirect to index after delete it
 }
开发者ID:ahmedzidan,项目名称:laravel,代码行数:13,代码来源:productcontroller.php


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