本文整理汇总了PHP中app\Product::sell方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::sell方法的具体用法?PHP Product::sell怎么用?PHP Product::sell使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::sell方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Factory::create();
$orders = Order::lists('id');
$products = Product::sell()->lists('id');
foreach (range(1, 45) as $index) {
if ($index > 29) {
$index -= 29;
}
OrderProduct::create(['order_id' => $orders[$index], 'product_id' => $faker->randomElement($products), 'quantity' => $faker->numberBetween(1, 3)]);
}
}
示例2: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit(Order $order, Product $product)
{
if (!$order->isAuthorized()) {
return redirect(route('orders.edit', [$order->id]))->with('error', 'You can\'t change product');
}
$products = Product::sell()->lists('name', 'id');
$pivot = $order->products()->find($product->id);
if (!$pivot) {
return redirect()->back()->with('error', 'This product don\'t belongs to that order');
}
$pivot = $pivot->pivot;
return view('orders.products.edit', compact('order', 'products', 'categories', 'product', 'pivot'));
}
示例3: create
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
$selectedProducts = [];
if (session()->has('products')) {
$selectedProducts = session()->pull('products');
}
$select = [0 => '-- Select --'];
$productsModel = Product::sell()->get();
$products = [];
foreach ($productsModel as $product) {
$products[$product->id] = $product->name . ' - price ' . $product->price;
}
if (Input::get('product') && empty($selectedProducts)) {
#product clicked from link
$selectedProducts[] = ['product_id' => Input::get('product'), 'quantity' => 1];
}
$products = $select + $products;
return view('orders.create', compact('products', 'selectedProducts'));
}