本文整理汇总了PHP中app\Product::whereId方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::whereId方法的具体用法?PHP Product::whereId怎么用?PHP Product::whereId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::whereId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create($orderId)
{
$order = Order::whereId($orderId)->select('id', 'type')->first();
$user = \Auth::user();
if ($user) {
//If a user is not trusted, send the error. Avoiding direct access routes to action by invalid user
if (!$user->isTrusted()) {
return redirect()->route('orders.show_cart', [$order->id])->withErrors(trans('freeproduct.unauthorized_access'));
}
//You can create free product from a sort order cart or wish list
if ($order->type != 'cart' && $order->type != 'wishlist') {
return redirect()->route('orders.show_cart', [$order->id])->withErrors(trans('freeproduct.order_type_invalid'));
}
//As is authorized to create, I check order detail
$order_content = OrderDetail::where('order_id', $order->id)->get();
//Sumatorial the total order to validate that the free product creator has enough points for the transaction
$total_points = 0;
foreach ($order_content as $orderDetail) {
$product = Product::whereId($orderDetail->product_id)->select('id', 'price')->first();
$total_points += $orderDetail->quantity * $product->price;
}
if ($user->current_points < $total_points) {
return redirect()->route('orders.show_cart')->withErrors(['main_error' => [trans('store.cart_view.insufficient_funds')]]);
}
$jsonOrder = json_encode($order_content->toArray());
$panel = $this->panel;
return view('freeproducts.create', compact('jsonOrder', 'panel', 'orderId'));
} else {
return redirect()->route('products')->withErrors(trans('freeproduct.unauthorized_access'));
}
}
示例2: update
public function update($id, $product)
{
Product::whereId($id)->update(['number' => $product['number'], 'name' => $product['name'], 'manufacturer_id' => $product['manufacturer_id'], 'model' => $product['model'], 'category_id' => $product['category_id'], 'price' => $product['price'], 'processor' => $product['processor'], 'memory' => $product['memory'], 'hdd' => $product['hdd'], 'graphics' => $product['graphics'], 'screen' => $product['screen'], 'optical' => $product['optical']]);
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Product $products)
{
//
$data = $request->all();
unset($data['_token']);
unset($data['_method']);
$data['created_by'] = \Auth::user()->id;
$data['updated_by'] = \Auth::user()->id;
$data['is_active'] = 1;
if (Input::file('image')) {
$destinationPath = 'img/product';
// upload path
$extension = Input::file('image')->getClientOriginalExtension();
// getting image extension
$fileName = rand(11111, 99999) . '.' . $extension;
// renameing image
$data['photo'] = $fileName;
Input::file('image')->move($destinationPath, $fileName);
// uploading file to given path
}
unset($data['image']);
$products->whereId(Input::get('id'))->update($data);
return Redirect::route('products.index');
}
示例4: showProduct
public function showProduct($id)
{
$product = Product::whereId($id)->first();
$setting = Setting::first();
return view('sites.showProduct', compact('product', 'setting'));
}