Skip to content

Commit 33b04a8

Browse files
committed
Docs.
1 parent 511f5ff commit 33b04a8

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

docs/docs/4.0/filtering/filtering.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,9 @@ You can use the following request to get sortable attributes for a repository:
302302
concatenate: `?only=sortables,matches, searchables` to get all of them at once.
303303
:::
304304

305-
## Eager loading - aka withs
305+
## Related
306306

307-
When get a repository index or details about a single entity, often we have to get the related entities (we have access
308-
to). This eager loading is configurable by Restify as following:
307+
When get a repository index or details about a single entity, often we have to get the related entities (we have access to). This eager loading is configurable by Restify as following:
309308

310309
```php
311310
public static $related = ['posts'];
@@ -336,7 +335,7 @@ public function foo() {
336335
}
337336
```
338337

339-
## Related eager
338+
## Related field
340339

341340
You can define an eager field to represent and serialize your data:
342341

@@ -356,6 +355,21 @@ public static function related(): array
356355

357356
You have the following relations available: `MorphToMany`, `MorphOne` `BelongsTo`, `HasOne`, `HasMany`, `BelongsToMany`.
358357

358+
This way you can restrict a specific relationship based on a user role:
359+
360+
```php
361+
use Binaryk\LaravelRestify\Fields\BelongsTo;use Illuminate\Http\Request;
362+
363+
public static function related(): array
364+
{
365+
return [
366+
'user' => BelongsTo::make('user', 'user', UserRepository::class)->canSee(function(Request $request) {
367+
return $request->user()->hasRole('owner');
368+
})
369+
];
370+
}
371+
```
372+
359373
### Custom data format
360374

361375
You can use a custom related cast class (aka transformer). You can do so by modifying the `restify.casts.related`

0 commit comments

Comments
 (0)