Monday 21 October 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...