0

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:

<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]);
}
Iftikhar uddin
  • 3,117
  • 3
  • 29
  • 48

3 Answers3

4

@if(Session::has('cart))

There is a typo here.

jeanj
  • 2,106
  • 13
  • 22
1

You missed a ' in the view

 @if(Session::has('cart))

You need to correct it

@if(Session::has('cart'))
Kiran LM
  • 1,359
  • 1
  • 16
  • 29
1

You left to put a ' at the first line of your View. it must be:

@if(Session::has('cart'))

jonju
  • 2,711
  • 1
  • 13
  • 19