Monday, 27 June 2016

php - Laravel Syntax error, unexpected 'variable' (T_STRING)





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

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...