Laravel Syntax error, unexpected 'variable' (T_STRING)
本问题已经有最佳答案,请猛点这里访问。
我试图访问用户的购物车视图,但当我单击以获取购物车视图时,它抛出以下错误。
Error : syntax error, unexpected 'item' (T_STRING)
Button:
1 2 | <i class="fa fa-shopping-cart" aria-hidden="true"> Shopping Cart <span class="badge">{{ Session::has('cart') ? Session::get('cart')->totalQty : '' }}</span> |
路线:
1 | Route::get('/shopping-cart','ProductController@getCart'); |
观点:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | @if(Session::has('cart)) <ul class="list-group"> @foreach($products as $product) <li class="list-group-item"> <span class="badge">{{ $product['qty'] }}</span> {{ $product['item']['title'] }} <span class="label label success">{{ $product['price'] }}</span> <button class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown"> Action <span class="carret"></span> </button> <ul class="dropdown-menu"> <li> Reduce By 1 </li> <li> Reduce By All </li> </ul> </li> @endforeach </ul> @endif |
推车控制器:
1 2 3 4 5 6 7 8 | 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]); } |
这里有个打字错误。
你走了,把一个
你错过了一个
1 | @if(Session::has('cart)) |
你需要纠正它
1 | @if(Session::has('cart')) |