Skip to content

Commit 784f537

Browse files
committed
Merge branch 'develop' into 3.x
2 parents 73a5f0d + 27258c0 commit 784f537

File tree

3 files changed

+72
-8
lines changed

3 files changed

+72
-8
lines changed

CHANGELOG.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,24 @@ All notable changes to this project will be documented in this file. This projec
1414
### Fixed
1515

1616
- **BREAKING** [#190](https://github.com/laravel-json-api/laravel/issues/190) The JSON:API media type now needs to be
17-
sent in the `Accept` header for a delete resource request. Previously there was no checking of the `Accept` media
17+
sent in the `Accept` header for a "delete" resource request. Previously there was no checking of the `Accept` media
1818
type, so anything could be sent. This is incorrect as the JSON:API specification shows the `Accept` header as
1919
`application/vnd.api+json` for [delete resource requests.](https://jsonapi.org/format/#crud-deleting)
2020

21+
## [2.6.0] - 2023-02-09
22+
23+
### Added
24+
25+
- New `MultiPaginator` that allows a schema to offer multiple different pagination strategies.
26+
27+
### Fixed
28+
29+
- The JSON:API rule validators for the follow query parameter fields all errored if a non-array value was provided. This
30+
is now fixed:
31+
- `fields`
32+
- `page`
33+
- `filter`
34+
2135
## [2.5.2] - 2023-01-25
2236

2337
### Fixed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
use LaravelJsonApi\Eloquent\Filters\Scope;
3333
use LaravelJsonApi\Eloquent\Filters\Where;
3434
use LaravelJsonApi\Eloquent\Filters\WhereIdIn;
35+
use LaravelJsonApi\Eloquent\Pagination\MultiPagination;
3536
use LaravelJsonApi\Eloquent\Pagination\PagePagination;
3637
use LaravelJsonApi\Eloquent\Schema;
3738
use LaravelJsonApi\Eloquent\SoftDeletes;
3839
use LaravelJsonApi\Eloquent\Sorting\SortCountable;
3940

4041
class PostSchema extends Schema
4142
{
42-
4343
use SoftDeletes;
4444

4545
/**
@@ -112,9 +112,15 @@ public function sortables(): iterable
112112
/**
113113
* @inheritDoc
114114
*/
115-
public function pagination(): PagePagination
115+
public function pagination(): MultiPagination
116116
{
117-
return PagePagination::make()->withoutNestedMeta();
117+
return new MultiPagination(
118+
PagePagination::make()->withoutNestedMeta(),
119+
PagePagination::make()
120+
->withoutNestedMeta()
121+
->withSimplePagination()
122+
->withPageKey('current-page')
123+
->withPerPageKey('per-page')
124+
);
118125
}
119-
120126
}

tests/dummy/tests/Api/V1/Posts/IndexTest.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use App\Models\Tag;
2424
use App\Models\User;
2525
use App\Tests\Api\V1\TestCase;
26+
use Faker\Generator;
2627
use Illuminate\Support\Arr;
2728
use Illuminate\Support\Facades\Date;
2829

@@ -79,7 +80,7 @@ public function testWithUser(): void
7980
$response->assertFetchedMany($expected);
8081
}
8182

82-
public function testPaginated(): void
83+
public function testPagePagination(): void
8384
{
8485
$posts = Post::factory()->count(5)->create();
8586

@@ -116,9 +117,52 @@ public function testPaginated(): void
116117
->page(['number' => 1, 'size' => 3])
117118
->get('/api/v1/posts');
118119

119-
$response->assertFetchedMany($expected)
120+
$response
121+
->assertFetchedMany($expected)
120122
->assertMeta($meta)
121-
->assertLinks($links);
123+
->assertExactLinks($links);
124+
}
125+
126+
public function testMultiPagination(): void
127+
{
128+
$posts = Post::factory()->count(6)->create([
129+
'created_at' => fn() => app(Generator::class)->dateTime(),
130+
])->sortByDesc('created_at')->values();
131+
132+
$expected = $this->identifiersFor('posts', $posts->skip(2)->take(2));
133+
134+
$meta = [
135+
'currentPage' => 2,
136+
'from' => 3,
137+
'perPage' => 2,
138+
'to' => 4,
139+
];
140+
141+
$links = [
142+
'first' => 'http://localhost/api/v1/posts?' . Arr::query([
143+
'page' => ['current-page' => 1, 'per-page' => 2],
144+
'sort' => '-createdAt',
145+
]),
146+
'next' => 'http://localhost/api/v1/posts?' . Arr::query([
147+
'page' => ['current-page' => 3, 'per-page' => 2],
148+
'sort' => '-createdAt',
149+
]),
150+
'prev' => 'http://localhost/api/v1/posts?' . Arr::query([
151+
'page' => ['current-page' => 1, 'per-page' => 2],
152+
'sort' => '-createdAt',
153+
]),
154+
];
155+
156+
$response = $this
157+
->jsonApi()
158+
->expects('posts')
159+
->page(['current-page' => 2, 'per-page' => 2])
160+
->get('/api/v1/posts');
161+
162+
$response
163+
->assertFetchedMany($expected)
164+
->assertMeta($meta)
165+
->assertExactLinks($links);
122166
}
123167

124168
public function testIncludeAuthor(): void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy