Skip to content

Commit 9b06977

Browse files
committed
[Feature] Add sort fields and default sort order for Eloquent schemas
Closes #14
1 parent be03b18 commit 9b06977

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file. This projec
77

88
### Added
99

10+
- [#14](https://github.com/laravel-json-api/laravel/issues/14) Additional sort parameters can now be added to Eloquent
11+
schemas. Previously only sortable attributes were supported. These new classes are added to schemas in the
12+
`sortables()` method.
13+
- Eloquent schemas now support a default sort order via the `$defaultSort` property.
1014
- [#74](https://github.com/laravel-json-api/laravel/issues/74) Developers can now add default include paths to the query
1115
request classes (e.g. `PostQuery` and `PostCollectionQuery`) via the `$defaultIncludePaths` property. These include
1216
paths are used if the client does not provide any include paths.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
"php": "^7.4|^8.0",
2727
"ext-json": "*",
2828
"laravel-json-api/core": "^1.0.0-beta.3",
29-
"laravel-json-api/eloquent": "^1.0.0-beta.3",
29+
"laravel-json-api/eloquent": "^1.0.0-beta.4",
3030
"laravel-json-api/encoder-neomerx": "^1.0.0-beta.1",
3131
"laravel-json-api/exceptions": "^1.0.0-beta.2",
3232
"laravel-json-api/spec": "^1.0.0-beta.1",
33-
"laravel-json-api/validation": "^1.0.0-beta.1",
33+
"laravel-json-api/validation": "^1.0.0-beta.2",
3434
"laravel/framework": "^8.0"
3535
},
3636
"require-dev": {

tests/dummy/app/JsonApi/V1/Posts/PostSchema.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use LaravelJsonApi\Eloquent\Pagination\PagePagination;
3535
use LaravelJsonApi\Eloquent\Schema;
3636
use LaravelJsonApi\Eloquent\SoftDeletes;
37+
use LaravelJsonApi\Eloquent\Sorting\SortCount;
3738
use LaravelJsonApi\HashIds\HashId;
3839

3940
class PostSchema extends Schema
@@ -93,6 +94,16 @@ public function filters(): array
9394
];
9495
}
9596

97+
/**
98+
* @inheritDoc
99+
*/
100+
public function sortables(): iterable
101+
{
102+
return [
103+
SortCount::make($this, 'comments'),
104+
];
105+
}
106+
96107
/**
97108
* @inheritDoc
98109
*/

0 commit comments

Comments
 (0)