本文整理汇总了PHP中app\Order::products方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::products方法的具体用法?PHP Order::products怎么用?PHP Order::products使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Order
的用法示例。
在下文中一共展示了Order::products方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Order
/** @test */
function an_order_consists_of_products()
{
$order = new Order();
$product = new Product('Fallout 4', 59);
$product2 = new Product('pillowcase', 7);
$order->add($product);
$order->add($product2);
$this->assertCount(2, $order->products());
}
示例2: finalizarCompra
public function finalizarCompra(Request $request)
{
$order = new Order();
$order->payment_method = 'visa';
$order->order_date = $now = date('Y-m-d H:i:s', strtotime('now'));
$order->source_name = $request['source_name'];
$order->source_address = $request['source_address'];
$order->source_email = $request['source_email'];
$order->amount = $request['amount'];
$order->save();
$order->products()->attach($request->session()->get('Product'));
$request->session()->flush();
return view('orders.finalizar_compra', ['personal_info' => $request, 'order_date' => $now, 'order_id' => $order->id]);
}
示例3: destroy
/**
* Remove the specified resource from storage.
* order product
* @param int $id
* @return Response
*/
public function destroy(Order $order, Product $product)
{
DB::transaction(function () use($product, $order) {
if ($order->status != 1) {
$product->update(['quantity' => $product->quantity + $order->products()->find($product->id)->pivot->quantity]);
}
$order->products()->detach($product->id);
});
return redirect(route('orders.edit', $order->id));
}