【发布时间】:2021-06-23 12:34:03
【问题描述】:
我正在使用 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>
而每个刀片,都遵循同样的结构,就像这样:
<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 表中有许多订单可用,遵循我之前写的那些特定状态。
如果我在Controller方法中dd()每个变量,它将在页面上成功打印数据,这意味着查询工作正常。
那么这里出了什么问题?如何正确显示数据?
【问题讨论】:
标签: php laravel eloquent laravel-8