php - 我需要帮助
问题描述
你好为什么我会收到这个错误?
我需要一点帮助!
有错误码!
ErrorException 为 foreach() 提供的参数无效(查看:F:\server\htdocs\yii\yumypizza\resources\views\shop\shopping-cart.blade.php)
这是我来自 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">{{ $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-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: {{ $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', ['products' => null]);
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
return view('shop.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
}
}
和路线。
Route::get('/add-to-cart/{id}', [
'uses' => 'ProductController@getAddToCart',
'as' => 'product.addToCart'
]);
Route::get('/shopping-cart', [
'uses' => 'ProductController@getCart',
'as' => 'product.shoppingCart'
]);
如果你能帮我解决这个问题!
解决方案
在紧凑函数中发送变量
$contents = $this->someFunction();
return view('admin.category.List', compact('contents'));
推荐阅读
- pandas - 使用 PM/AM 将字符串更改为日期时间
- ios - UIAlertController 出现后自动关闭一小部分时间
- react-native - 尝试在反应本机应用程序上运行 jest 时测试失败。找不到“setupDevtools”错误
- android - 有什么方法可以将 FCM 消息传递的延迟控制在 1 分钟内?
- java - 我正在尝试为选择排序创建一个并行实现,但它最终比串行慢
- python - python3如何将unicode代码点转换为unicode char
- machine-learning - BLEU 分数如何运作?. 它与简单的基于 Jaccard 分数的相似性预测有何不同?
- r - R“draw.quad.venn 中的错误,不可能:产生负面积”尽管数字是正确的
- mercurial - 内部合并工具(merge-other)是“找不到”?
- laravel-5 - 将laravel重定向到角度路线