Hager Aly
Hager Aly

Reputation: 1143

laravel api handler how to order by a child column

I'm using laravel API handler and I was wondering on how to send a request to order by a column from 'with' table

Here is my backend code

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

and the request-url

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

Upvotes: 1

Views: 157

Answers (1)

ajameswolf
ajameswolf

Reputation: 1660

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

Something like that should do.

Upvotes: 1

Related Questions