本文整理汇总了PHP中app\models\Product::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::findOrFail方法的具体用法?PHP Product::findOrFail怎么用?PHP Product::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Product
的用法示例。
在下文中一共展示了Product::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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('products');
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update($id, Request $request)
{
$this->validate($request, ['name' => 'required', 'description' => 'required', 'category_id' => 'required', 'purchase_price' => 'required', 'price' => 'required']);
$product = Product::findOrFail($id);
$product->update($request->all());
Session::flash('flash_message', 'Product updated!');
return redirect('backoffice/products');
}
示例3: showProduct
public function showProduct(Request $request, $id)
{
$product = Product::findOrFail($id);
$active_menu = '';
$topics = Topic::getProductTopics($id);
$product_detail_topic = $product->detailTopic;
return view('product', compact(['product', 'active_menu', 'topics', 'product_detail_topic']));
}
示例4: update
public function update(Request $request, $id)
{
$product = Product::findOrFail($id);
$data = $request->only(['', '', '', '']);
$product->fill($data);
$product->save();
return redirect()->action('ProductController@index');
//PUT /resource/1
//
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response|null
*/
public function store(Request $request)
{
/**
* @var $user \App\User
*/
$user = \Auth::user();
if (!$user) {
return null;
}
$product_id = $request->get('product_id');
$product_model = \App\Models\Product::findOrFail($product_id);
$sql = 'INSERT IGNORE INTO ' . \App\Models\OrderedProduct::TABLE . ' (created_at, user_id, product_id, catalog_id, is_deferred) ' . 'VALUES (now(), ?, ?, ?, 1)';
\DB::insert($sql, [$user->id, $product_id, $product_model->catalog_id]);
return ['calls' => [['call' => 'updateHtmlContext', 'params' => ['#product-mini-item-' . $product_id, view('catalog.product_mini_item', ['product' => $product_model])->render()]], ['call' => 'updateHtmlContext', 'params' => ['#basket-mini-box', view('basket.mini_box')->render()]], ['call' => 'updateHtmlContext', 'params' => ['#basket-orders-container', view('basket.orders_items')->render()]]]];
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response|null
*/
public function store(Request $request)
{
/**
* @var $user \App\User
*/
$user = \Auth::user();
if (!$user) {
return null;
}
$product_id = $request->get('product_id');
$product_model = \App\Models\Product::findOrFail($product_id);
$sql = 'INSERT INTO ' . \App\Models\OrderedProduct::TABLE . ' (created_at, user_id, product_id, catalog_id, price, quantity) ' . 'VALUES (now(), ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE quantity = quantity + ?, updated_at = now()';
$public_price = $product_model->getPublicPrice();
$quantity = $request->get('quantity');
\DB::insert($sql, [$user->id, $product_id, $product_model->catalog_id, $public_price, $quantity, $quantity]);
return ['calls' => [['call' => 'updateHtmlContext', 'params' => ['#product-mini-item-' . $product_id, view('catalog.product_mini_item', ['product' => $product_model])->render()]], ['call' => 'updateHtmlContext', 'params' => ['#basket-mini-box', view('basket.mini_box')->render()]], ['call' => 'updateHtmlContext', 'params' => ['#basket-orders-container', view('basket.orders_items')->render()]]]];
}
示例7: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$product = Product::findOrFail($id);
$rating_cont = Comment::where('product_id', '=', $product->id)->count();
$checked_rating_count = $rating_cont > 0 ? $rating_cont : 1;
$five_star = Comment::where('product_id', '=', $product->id)->where('rating', '=', '5')->count() * 100 / $checked_rating_count;
$four_star = Comment::where('product_id', '=', $product->id)->where('rating', '=', '4')->count() * 100 / $checked_rating_count;
$three_star = Comment::where('product_id', '=', $product->id)->where('rating', '=', '3')->count() * 100 / $checked_rating_count;
$two_star = Comment::where('product_id', '=', $product->id)->where('rating', '=', '2')->count() * 100 / $checked_rating_count;
$one_star = Comment::where('product_id', '=', $product->id)->where('rating', '=', '1')->count() * 100 / $checked_rating_count;
$owner = $product->owner();
$mods = $product->mods();
if (empty($product)) {
Flash::error('Product not found');
return redirect(route('admin.products.index'));
}
return view('site.products.show')->with(['product' => $product, 'rating_count' => $rating_cont, 'five_star' => $five_star, 'four_star' => $four_star, 'three_star' => $three_star, 'two_star' => $two_star, 'one_star' => $one_star, 'owner' => $owner, 'mods' => $mods]);
}
示例8: getActualOffersProducts
public static function getActualOffersProducts()
{
return \App\Models\ProductInPurchase::paginate(20);
return \App\Models\Product::where('status', '=', 1)->paginate(20);
$sql = "select ps.product_id\n from catalogs ct\n join products_offers ps on ct.id = ps.catalog_id\n where ct.status = 1 and ps.status = 1 limit 20";
$products_ids_obj_arr = \DB::select($sql);
if (empty($products_ids_obj_arr)) {
return [];
}
$products = [];
foreach ($products_ids_obj_arr as $product_obj) {
$products[] = \App\Models\Product::findOrFail($product_obj->product_id);
}
//print_r($products); exit;
return $products;
$products = \App\Models\Product::where('status', '>', 0)->where('price_1', '>', 0)->paginate(20);
return $products;
}
示例9: add
public function add($id)
{
$order = Order::where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->first();
//$orderItem = $order->items()->findOrFail($id);
//$productId = $order->items()->findOrFail($itemId);
$orderItem = $order->items()->where('product_id', '=', (int) Input::get("product_id"))->first();
if ($orderItem) {
$orderItem->quantity += (int) Input::get("quantity");
$orderItem->save();
} else {
$product = Product::findOrFail((int) Input::get("product_id"));
$orderItem = new OrderItem();
$orderItem->order_id = $id;
$orderItem->product_id = $product->id;
$orderItem->price = $product->price;
$orderItem->quantity = (int) Input::get("quantity");
$orderItem->save();
}
$this->recalculateDelivery($order);
return $this->orderToJson($order);
}
示例10: index
/**
* Display Generator Page
* @param $product_id
* @return $this
*/
public function index($product_id)
{
$product = $this->product->findOrFail($product_id);
return view('products.codes.index', compact('product'))->with('codes', $product->codes()->simplePaginate());
}
示例11: destroy
public function destroy(Request $request, $id)
{
Product::findOrFail($id)->delete();
return redirect()->route('product.index')->with('success_message', 'The product has been successfully deleted.');
}
示例12: addItem
public function addItem($product_id, $quantity)
{
$product = Product::findOrFail($product_id);
$params = ['order_id' => $this->id, 'product_id' => $product->id, 'quantity' => $quantity, 'price' => $product->price * $quantity];
return OrderItem::create($params);
}
示例13: show
/**
* Display the specified resource.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$product = Product::findOrFail($id);
return view('frontoffice.products.show', compact('product'));
}
示例14: edit
public function edit($id)
{
$product = Product::findOrFail($id);
return view('productStockInitializations.edit', compact('product'));
}
示例15: edit
public function edit($id)
{
$data = Product::findOrFail($id);
$select = Category::all('id', 'menu_name');
return view('admin.product.edit', ['data' => $data, 'select' => $select]);
}