Skip to content

Commit ef46473

Browse files
committed
docs.
1 parent fe628f5 commit ef46473

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/docs/4.0/filtering/filtering.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,24 @@ This will return all posts, sorted descending by users name.
272272
As you may notice we have typed twice the `users.name` (on the array key, and as argument in the `setColumn` method). As soon as you use the fully qualified key name, you can avoid the `setColumn` call, since the column will be injected automatically based on the `sorts` key.
273273
:::
274274

275+
### Sort using closure
276+
277+
If you have a quick sort method, you can use a closure to sort your data:
278+
279+
```php
280+
// PostRepository
281+
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
282+
283+
public static function sorts(): array
284+
{
285+
return [
286+
'users.name' => function(RestifyRequest $request, $query, $direction) {
287+
// custom sort
288+
}
289+
];
290+
}
291+
```
292+
275293
### Get available sorts
276294

277295
You can use the following request to get sortable attributes for a repository:

0 commit comments

Comments
 (0)