Skip to content

Commit ab96aa6

Browse files
committed
Merge branch 'release/2.3.0'
2 parents 606f78e + f25e476 commit ab96aa6

File tree

7 files changed

+1895
-1639
lines changed

7 files changed

+1895
-1639
lines changed

1.0/requests/authorization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ we can register it for multiple resource types as follows:
641641

642642
```php
643643
use App\JsonApi\Authorizers\BlogAuthorizer;
644-
use LaravelJsonApi\LaravelJsonApi;
644+
use LaravelJsonApi\Laravel\LaravelJsonApi;
645645

646646
public function register(): void
647647
{
@@ -668,7 +668,7 @@ To register your default implementation, use the `register` method of your
668668

669669
```php
670670
use App\JsonApi\Authorizers\DefaultAuthorizer;
671-
use LaravelJsonApi\LaravelJsonApi;
671+
use LaravelJsonApi\Laravel\LaravelJsonApi;
672672

673673
public function register(): void
674674
{

1.0/tutorial/08-fetching-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ have a `UserFactory.php` file that helps us create `User` models.
268268
Add a factory for our `Post` model using the following command:
269269

270270
```bash
271-
vendor/bin/sail make:factory PostFactory
271+
vendor/bin/sail artisan make:factory PostFactory
272272
```
273273

274274
That will create the `database/factories/PostFactory.php` file. Open that up

2.0/requests/authorization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ we can register it for multiple resource types as follows:
641641

642642
```php
643643
use App\JsonApi\Authorizers\BlogAuthorizer;
644-
use LaravelJsonApi\LaravelJsonApi;
644+
use LaravelJsonApi\Laravel\LaravelJsonApi;
645645

646646
public function register(): void
647647
{
@@ -668,7 +668,7 @@ To register your default implementation, use the `register` method of your
668668

669669
```php
670670
use App\JsonApi\Authorizers\DefaultAuthorizer;
671-
use LaravelJsonApi\LaravelJsonApi;
671+
use LaravelJsonApi\Laravel\LaravelJsonApi;
672672

673673
public function register(): void
674674
{

2.0/schemas/eager-loading.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,26 @@ As this relationship endpoint returns `comments` resources, the allowed
131131
include paths are determined by the `CommentSchema` class.
132132
:::
133133

134+
### Conditionally Disabling on Specific Relations
135+
136+
If you need to conditionally disable eager-loading on a relationship, use
137+
the `canEagerLoad()` method. You can provide a boolean, for example:
138+
139+
```php
140+
HasMany::make('comments')->canEagerLoad(
141+
Gate::allows('viewComments', Post::class),
142+
)
143+
```
144+
145+
Alternatively, you can provide a callback to determine if eager loading is
146+
allowed:
147+
148+
```php
149+
HasMany::make('comments')->canEagerLoad(
150+
fn() => Gate::allows('viewComments', Post::class),
151+
)
152+
```
153+
134154
## Disabling On A Resource Type
135155

136156
To disable eager loading for a resource type, set the `$maxDepth` property

2.0/schemas/filters.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Laravel JSON:API ships with the following filters:
243243
- [WhereIdNotIn](#whereidnotin)
244244
- [WhereIn](#wherein)
245245
- [WhereNotIn](#wherenotin)
246+
- [WhereNull / WhereNotNull](#wherenull-wherenotnull)
246247
- [WherePivot](#wherepivot)
247248
- [WherePivotIn](#wherepivotin)
248249
- [WherePivotNotIn](#wherepivotnotin)
@@ -645,6 +646,40 @@ string values if a delimiter is set:
645646
WhereNotIn('not-category', 'category')->delimiter(',')
646647
```
647648

649+
### WhereNull / WhereNotNull
650+
651+
The `WhereNull` and `WhereNotNull` filters can be used to filter resources
652+
by a column that supports `null` values. The use of these two filters is
653+
best explained using an example.
654+
655+
Imagine a scenario where a `Post` model has a `published_at` column. The
656+
value in this column indicates whether the blog post has been published.
657+
If it holds `null`, the blog post is not published (aka is a draft post).
658+
If it holds a date time, the blog post is published.
659+
660+
In this scenario, you would use the `WhereNull` filter like this:
661+
662+
```php
663+
WhereNull::make('draft', 'published_at')
664+
```
665+
666+
In this case, if the client provided `true` as the `draft` filter value,
667+
the response would contain resources where the column value is `null` -
668+
i.e. the blog posts are draft posts. Providing `false` as the filter
669+
value would result in blog posts that are not draft, i.e. published.
670+
671+
Alternatively, you could use the `WhereNotNull` filter like this:
672+
673+
```php
674+
WhereNotNull::make('published', 'published_at')
675+
```
676+
677+
In this case, if the client provided `true` as the `published` filter
678+
value, the response would contain resources where the column value is
679+
a date time - i.e. the blog posts are published. Providing `false`
680+
as the filter value would result in blog posts that are not published,
681+
i.e. are draft and have a `null` value for the column.
682+
648683
### WherePivot
649684

650685
The `WherePivot` filter can be used on a

2.0/tutorial/08-fetching-resources.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ have a `UserFactory.php` file that helps us create `User` models.
268268
Add a factory for our `Post` model using the following command:
269269

270270
```bash
271-
vendor/bin/sail make:factory PostFactory
271+
vendor/bin/sail artisan make:factory PostFactory
272272
```
273273

274274
That will create the `database/factories/PostFactory.php` file. Open that up

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