本文整理汇总了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;
}
示例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]);
}
示例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');
}
示例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');
}
}
示例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;
}
}
示例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));
}
}
示例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']);
}
}
示例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');
}
示例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'));
}
示例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'));
}
示例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()));
}
}
示例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
}