Thursday, July 4, 2019

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

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...