Laravel 语法错误,意外的“变量”(T_STRING)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38652052/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Syntax error, unexpected 'variable' (T_STRING)
提问by Iftikhar uddin
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)
错误:语法错误,意外的“项目”(T_STRING)
Button:
按钮:
<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:
路线:
Route::get('/shopping-cart','ProductController@getCart');
View:
查看:
@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
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]);
}
回答by jeanj
@if(Session::has('cart))
@if(Session::has('cart))
There is a typo here.
这里有一个错字。
回答by Kiran LM
You missed a ' in the view
你在视图中错过了一个 '
@if(Session::has('cart))
You need to correct it
你需要纠正它
@if(Session::has('cart'))
回答by jonju
You left to put a '
at the first line of your View. it must be:
您离开后将 a'
放在您的视图的第一行。肯定是:
@if(Session::has('cart'))
@if(Session::has('cart'))