我正在尝试访问用户的购物车视图,但是当我点击获取购物车视图时,它会抛出以下错误。
错误:语法错误,意外'项目' (T_STRING)
按钮:
<a href="{{ url('shopping-cart') }}"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Shopping Cart
<span class="badge">{{ Session::has('cart') ? Session::get('cart')->totalQty : '' }}</span>
</a>
路线:
Route::get('/shopping-cart','ProductController@getCart');
查看:
@if(Session::has('cart))
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<ul class="list-group">
@foreach($products as $product)
<li class="list-group-item">
<span class="badge">{{ $product['qty'] }}</span>
<strong>{{ $product['item']['title'] }}</strong>
<span class="label label success">{{ $product['price'] }}</span>
<div class="btn-group">
<button class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown">
Action <span class="carret"></span>
</button>
<ul class="dropdown-menu">
<li><a href="$">Reduce By 1</a></li>
<li><a href="$">Reduce By All</a></li>
</ul>
</div>
</li>
@endforeach
</ul>
</div>
</div>
@endif
推车控制器:
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]);
}
答案 0 :(得分:4)
@if(Session::has('cart))
这里有一个错字。
答案 1 :(得分:1)
你错过了一个&#39;在视图中
@if(Session::has('cart))
你需要纠正它
@if(Session::has('cart'))
答案 2 :(得分:1)
您离开时将'
放在视图的第一行。它一定是:
@if(Session::has('cart'))