【问题标题】:How can i parse the query builder result?如何解析查询生成器结果?
【发布时间】:2026-01-12 02:15:01
【问题描述】:

我使用查询生成器从数据库中选择数据。我的查询生成器是:

    $end_date = DB::table('synon_library_lending')
    ->where('end_date', '<', Carbon::today())
    ->pluck('end_date', 'id');

这个查询的结果是: {"4":"2019-07-03","5":"2019-07-04"} 我的问题是:我无法在 php 中解析上述语句? 您对此问题的解决方案是什么?

【问题讨论】:

标签: php laravel parsing foreach query-builder


【解决方案1】:

要显示查询生成器的结果,请使用 foreach,如下代码:

 $lists = User::orderBy('first_name')
        ->orderBy('last_name')->get();
    if ($lists->count()) {
        foreach ($lists as $item) {
            $list[$item->id] = "$item->first_name $item->last_name";
        }
    }

【讨论】: