Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 数据排序问题,排序功能_Laravel_Sorting - Fatal编程技术网

Laravel 数据排序问题,排序功能

Laravel 数据排序问题,排序功能,laravel,sorting,Laravel,Sorting,对不起,可能是个愚蠢的问题,但我对排序结果有问题,我只想按更新的\u at->data,降序排序结果,所以最新的记录在顶部 public function boostsRequest() { $boosts = Cache::remember('boosts_all', 30, function () { $raw = Boost::where('status', 3)->where('hidden', false)->with('screenshot')-&

对不起,可能是个愚蠢的问题,但我对排序结果有问题,我只想按更新的\u at->data,降序排序结果,所以最新的记录在顶部

public function boostsRequest()
{
    $boosts = Cache::remember('boosts_all', 30, function () {
        $raw = Boost::where('status', 3)->where('hidden', false)->with('screenshot')->get();

        $raw->transform(function ($boost) {
            return [
                'currentdivision' => $boost->currentdivision,
                'desireddivision' => $boost->desireddivision,
                'wins' => $boost->wins,
                'type' => $boost->type,
                'screenshot' => optional($boost->screenshot)->url,
                'updated_at' => $boost->updated_at,
            ];
        });

        $raw = $raw->sortBy(function ($boost) {
            return strtotime($boost->updated_at->date);
        });            

        return $raw;
    });

    return $boosts;
}
通常,函数调用的结果是一个JSON表,其中填充了具有以下结构的对象:

{“currentdivision”:“12”,“desireddivision”:“16”,“wins”:null,“type”:“division”,“screenshot”:“https:\/\/ucarecdn.com\/86c6d345-1a7f-4af4-8005-175ee235ccd8\/”,“更新时间:{“date”:“2016-11-03 11:11:26.000000”,“时区类型”:3,“时区”:“UTC”}


我希望有一个对象表,按字段
updated\u at->date
排序,降序,因此最近更新的对象作为第一个更新的\u at值不是对象,只需删除
->date
部分,只需要此代码

返回strotime($boost->updated_at);

提示:有时,当我们对值的表示方式或php函数在表记录上的行为表示怀疑时,我们可以使用tinker:D.

更新的值不是对象,只需删除
->date
部分,只需此代码即可

返回strotime($boost->updated_at);

提示:有时,当我们对值的表示方式或php函数在表记录上的行为表示怀疑时,我们可以使用tinker:D.

只需在有说服力的请求中按更新时间对集合进行排序:

$raw = Boost::where('status', 3)->where('hidden', false)->with('screenshot')->orderBy('updated_at')->get();

对于
updated_at
值,您可以确定它存在于数据库中。不需要关闭

只需在雄辩的请求中按更新的时间对集合进行排序:

$raw = Boost::where('status', 3)->where('hidden', false)->with('screenshot')->orderBy('updated_at')->get();

对于
updated_at
值,您可以确定它存在于数据库中。不需要关闭

到底是什么问题?你有错误吗?还是排序不起作用了?只是更新了我的帖子。到底是什么问题?你有错误吗?还是排序不起作用?只是更新了我的帖子