php - Laravel 8:雄辩的查询似乎显示从数据库中检索到的数据
问题描述
我正在使用 Laravel 8 开发基本的在线订购系统,目前我有一个名为的表orders
,每个订单都可以具有以下状态之一:
suspending
, awaiting
, verified
, confirmed
, ignored
, 和rejected
.
所以在控制器上,我编写了这个代码:
public function index()
{
$uid = auth()->user()->id;
$suspendeds = Order::where('status', 'suspending')->where('user_id', $uid)->latest()->paginate(2);
$awaitings = Order::where('status', 'awaiting')->where('user_id', $uid)->latest()->paginate(2);
$verified = Order::where('status', 'verified')->where('user_id', $uid)->latest()->paginate(2);
$confirmed = Order::where('status', 'confirmed')->where('user_id', $uid)->latest()->paginate(2);
$canceled = Order::whereIn('status', ['rejected','ignored'])->where('user_id', $uid)->latest()->paginate(2);
return view('profile.index', compact(['suspendeds','awaitings','verified','confirmed','canceled']));
}
然后在 Blade 上,我添加了这个:
<div class="profile-body BKoodakBold">
@include('profile.orders.suspends')
@include('profile.orders.awaites')
@include('profile.orders.verifies')
@include('profile.orders.confirms')
@include('profile.orders.cancels')
</div>
每个 Blade 都遵循相同的结构,就像这样:
<tbody>
@foreach($verified as $verify)
<tr>
<td><input class="form-control" type="text" value="{{ $verify->title }}" disabled="disabled"></td>
<td><input class="form-control" type="text" value="{{ $verify->material }}" disabled="disabled"></td>
<td><input class="form-control" type="text" value="{{ $verify->color }}" disabled="disabled"></td>
<td><input class="form-control"type="text" value="{{ $verify->description }}" disabled="disabled"></td>
</tr>
@endforeach
</tbody>
但现在的问题是,它根本没有显示任何东西!orders
但是,在我之前写的那些特定状态之后,桌上有许多可用的订单。
而且,如果我dd()
在 Controller 方法中使用每个变量,它将在页面上成功打印数据,这意味着查询工作正常。
那么这里出了什么问题呢?如何正确显示数据?
解决方案
您只需要为子视图提供变量
@include('profile.orders.suspends', ['suspends' => $suspends])
@include('profile.orders.awaites', ['awaites' => $awaites])
@include('profile.orders.verifies', ['verifies' => $verifies])
@include('profile.orders.confirms', ['confirms' => $confirms])
@include('profile.orders.cancels', ['cancels' => $cancels])
推荐阅读
- python - Django url - 使用 {% include %} 时不允许直接打开
- javascript - 电子窗口显示屏幕截图
- powershell - 具有错误处理功能的 Powershell TCP 客户端
- php - Loop Year and Months
- c - 从 2d char 数组指针中获取一个字符,该指针是 C 中结构指针的属性
- webpack - 如何使用 webpack-cli init 指定 webpack 配置文件名?
- javascript - jQuery如何找到存储在数组中的最后一个HTML元素
- virtocommerce - Virto Commerce 无法在 B2B 主题中添加报价功能
- python-3.x - Calling vcvarsall.bat in Python and using its env variables
- javascript - Connecting to Neo4j with Javascript (without drivers)