Sorting
In order to request results to be sorted, you can use the orderBy()
method. It accepts two arguments:
$field
:string|array
Name of field or key-value pair, where key = field, value = sorting order.$direction
:string
(optional) sorting order, e.g.asc
ordesc
.
$response = $client
->orderBy('name')
->orderBy('age', 'desc')
->get('/users');
default
/users?sort=name asc,age desc
json api
/users?sort=name,-age
odata
/users?$orderby=name asc,age desc
Via Array
You can also use an array as argument. When doing so, the second argument is ignored.
$response = $client
->orderBy([
'name' => 'desc',
'age',
'jobs' => 'asc'
])
->get('/users');
default
/users?sort=name desc,age asc,jobs asc
json api
/users?sort=-name,age,jobs
odata
/users?$orderby=name desc,age asc,jobs asc