Beispiel #1
0
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         Cart::create([]);
     }
 }
 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');
 }
 /**
  * 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');
 }
 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');
 }