【问题标题】:How can i parse the query builder result?如何解析查询生成器结果?
【发布时间】:2019-12-06 20:08:54
【问题描述】:

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

    $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";
        }
    }

【讨论】:

    猜你喜欢
    • 2019-06-22
    • 2019-07-25
    • 1970-01-01
    • 2015-12-18
    • 2021-09-12
    • 2015-04-19
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多