I am trying to access a Shopping Cart view of a user, but when i click to get the Cart View it throws the below error.
Error : syntax error, unexpected 'item' (T_STRING)
Button:
Shopping Cart
{{ Session::has('cart') ? Session::get('cart')->totalQty : '' }}
Route:
Route::get('/shopping-cart','ProductController@getCart');
View:
@if(Session::has('cart))
@foreach($products as $product)
{{ $product['qty'] }}
{{ $product['item']['title'] }}
{{ $product['price'] }}
@endforeach
@endif
Cart Controller:
public function getCart(){
if(!Session::has('cart')){
return view('shop.shopping-cart');
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
}
Answer
@if(Session::has('cart))
There is a typo here.
No comments:
Post a Comment