laravel api处理程序如何通过子列进行排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了laravel api处理程序如何通过子列进行排序相关的知识,希望对你有一定的参考价值。

我正在使用laravel API handler,我想知道如何通过'with'表中的列发送请求

这是我的后端代码

$query = Product::query();
    $query->company();
    $query->with('category'); $result=ApiHandler::parseMultiple($query);
    return $result->getResponse(); 

和请求网址

http://localhost/public/api/v1/product/view/0?&_offset=0&_limit=10&_config=meta-total-count,meta-filter-count&_sort=-category.category_name

答案
$query = Product::getModel()
->newQuery()
->select('products.*','categories.*')
->join('categories','product.category_id,'=','categories.id')
->orderBy('category.sort_order');

这样的事应该做​​。

以上是关于laravel api处理程序如何通过子列进行排序的主要内容,如果未能解决你的问题,请参考以下文章