【问题标题】:Laravel 8: Eloquent Query Does Seem To Showing Retrieved Data From the DbLaravel 8:雄辩的查询似乎显示从数据库中检索到的数据
【发布时间】:2021-06-23 12:34:03
【问题描述】:

我正在使用 Laravel 8 开发基本的在线订购系统,目前我有一个名为 orders 的表,每个订单可以具有以下状态之一:

suspendingawaitingverifiedconfirmedignoredrejected

所以在控制器,我编写了这个代码:

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


    【解决方案1】:

    您只需要为子视图提供变量

      @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])
    

    【讨论】:

    • 你可以只传递变量`@include('profile.orders.suspends', $suspends)`
    猜你喜欢
    • 2020-06-03
    • 1970-01-01
    • 2022-08-05
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-05
    • 2018-01-26
    相关资源
    最近更新 更多