本文整理汇总了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);
}
示例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);
}
示例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');
}
示例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);
}
示例5: show
public function show($id)
{
$product = Product::findOrFail($id);
//return $id;
//dd($product);
return view('pages.detail', compact('product'));
}
示例6: destroy
public function destroy($id, Request $request)
{
$product = Product::findOrFail($id);
$product->delete();
$request->session()->flash('message', 'Medicine successfuly deleted');
return redirect()->back();
}
示例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'));
}
示例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'));
}
示例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'));
}
示例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'];
}
示例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.');
}
示例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]);
}
示例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'));
}
示例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);
}
示例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'));
}