在Laravel排序

时间:2017-08-17 11:43:29

标签: php laravel laravel-5 php-7

我有这样的功能秀:

public function show($post)
{
    $post = Post::whereId($post)->filter(\Request::only(['fields']))->firstOrFail();

    return Response::json($post);
}

如何添加此功能sortBy('我发送的表格中的某些字段')

1 个答案:

答案 0 :(得分:0)

只是做:

    $post = Post::whereId($post)->filter(\Request::only(['fields']))->orderBy('desired_field','ASC')->firstOrFail();