本文整理汇总了PHP中Cart::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Cart::create方法的具体用法?PHP Cart::create怎么用?PHP Cart::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cart
的用法示例。
在下文中一共展示了Cart::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
$faker = Faker::create();
foreach (range(1, 10) as $index) {
Cart::create([]);
}
}
示例2: postAddtocart
public function postAddtocart()
{
$product = Product::find(Input::get('id'));
$quantity = Input::get('quantity');
$member_id = Auth::user()->id;
Cart::create(array('product_id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image, 'member_id' => $member_id));
return Redirect::to('store/cart');
}
示例3: store
/**
* Store a newly created cart in storage.
*
* @return Response
*/
public function store()
{
$validator = Validator::make($data = Input::all(), Cart::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
Cart::create($data);
return Redirect::route('carts.index');
}
示例4: postAddToCart
public function postAddToCart()
{
//validation
$rules = ['amount' => 'required|numeric', 'book' => 'required|numeric|exists:books,id'];
//inputs, rules
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::route('index')->with('error', 'The book could not be added to your cart');
}
$member_id = Auth::user()->id;
$book_id = Input::get('book');
$amount = Input::get('amount');
$book = Book::find($book_id);
$total = $amount * $book->price;
//checking existing in the cart
$count = Cart::where('book_id', '=', $book_id)->where('member_id', '=', $member_id)->count();
if ($count) {
return Redirect::route('index')->with('error', 'The book already exists in your cart.');
}
Cart::create(['member_id' => $member_id, 'book_id' => $book_id, 'amount' => $amount, 'total' => $total]);
return Redirect::route('cart');
}