Я изучаю PHP Laravel и разрабатываю проект корзины покупок. Я могу добавить товар в список, но, когда нажимаю на ссылку «Корзина». Я получаю следующую ошибку.
Facade \ Ignition \ Exceptions \ ViewException Предоставлен неверный аргумент для foreach () (Просмотр: C: \ Users \ Khundokar Nirjor \ Desktop \ Учебное пособие \ laravel \ shopping-cart \ resources\ views \ shop \ shopping-cart.blade.php)
Вот мой маршрутизатор
Route::get('/shopping-cart',[
'uses' => 'ProductController@getCart',
'as' => 'product.shopppingCart'
]);
Вот мой код header.blade.php.
<nav class="navbar navbar-default">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Brand</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="{{route ('product.shopppingCart')}}"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Shopping Cart
<span class="badge">{{ Session::has('cart') ? Session::get('cart')->totalQty : '' }}</span>
</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-user" aria-hidden="true"></i> User Mangemetn <span class="caret"></span></a>
<ul class="dropdown-menu">
@if(Auth:: check())
<li><a href="{{ route('user.profile')}}">User Profile</a></li>
<li><a href="{{ route('user.logout')}}">Logout</a></li>
@else
<li><a href="{{ route('user.signup')}}">Sign Up</a></li>
<li><a href="{{ route('user.signin')}}">Sign In</a></li>
@endif
<li role="separator" class="divider"></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
Вот мой shopping-cart.blade.php
@extends('layouts.master')
@section('title')
Laravel Shopping Cart
@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"> {{ $product['qty'] }}</span>
<strong >{{ $product['item']['title']}}</strong>
<span class ="label label-success"> {{ $product['price']}}</span>
<div class="btn-group">
<button type="button" class="btn btn-primary btn-xs dropdown-toggle" 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 : {{ $totalPrice}}</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>
<div class ="row">
<div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
<strong>Total : {{$totalPrice}} </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
Вот мой код контроллера
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]);
}
Вот снимок экрана, когда я нажал на ссылку корзины покупок
![enter image description here](https://i.stack.imgur.com/Qog7S.png)