Hello why i get this error?
I need small help!
There is Error code!
ErrorException Invalid argument supplied for foreach() (View: F:\server\htdocs\yii\yumypizza\resources\views\shop\shopping-cart.blade.php)
here is my code from shop.shopping-cart
@extends('layouts.master')
@section('title')
THE YUMMI PIZZA
@endsection
@section('content')
@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"></span>
<strong></strong>
<span class="label label-success"></span>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-xs dropdown-toogle" data-toggle="dropdown">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="">Reduce by 1</a></li>
<li><a href="">Reduce All</a></li>
</ul>
</div>
</li>
@endforeach
</ul>
</div>
</div>
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<strong> Total: </strong>
</div>
</div>
<hr>
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<button type="button" class="btn btn-success">CheckOut</button>
</div>
</div>
@else
<div class="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<h2>No Items in Cart!</h2>
</div>
</div>
@endif
@endsection
and here is my controller function code.
public function getCart() {
if (!Session::has('cart')) {
return view('shop.shopping-cart', ['products' => null]);
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
}
}
and Route.
Route::get('/add-to-cart/{id}', [
'uses' => 'ProductController@getAddToCart',
'as' => 'product.addToCart'
]);
Route::get('/shopping-cart', [
'uses' => 'ProductController@getCart',
'as' => 'product.shoppingCart'
]);
If you can help me about this !
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire