當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。