Skip to content

Commit 7a3ef41

Browse files
committed
wip
1 parent 417df1e commit 7a3ef41

File tree

1 file changed

+40
-2
lines changed

1 file changed

+40
-2
lines changed

fields.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,53 @@ $field = URL::make(__('GitHub Profile'), 'gh_profile');
522522

523523
Relation fields are representing Eloquent relation definitions on the resource models. Relation fields are highly customizable and provide a nice and detailed API.
524524

525+
### Configuration
526+
527+
### Searchable & Sortable Columns
528+
529+
#### Customizing the Query
530+
531+
You may customize the relatable model's query. This is possible defining global scopes per field type or locally on the field definition.
532+
533+
You may apply global customization using the `scopeQuery` static method:
534+
535+
```php
536+
use Illuminate\Database\Eloquent\Builder;
537+
use Illuminate\Database\Eloquent\Model;
538+
use Illuminate\Http\Request;
539+
540+
Media::scopeQuery(function (Request $request, Builder $query, Model $model): Builder {
541+
return $query->where('user_id', $request->user()->getKey());
542+
});
543+
```
544+
545+
> This will apply the query resolution logic to all `Media` fields.
546+
547+
You may apply local customization using the `withRelatableQuery` method:
548+
549+
```php
550+
$field->withRelatableQuery(function (Request $request, Builder $query, Model $model): Builder {
551+
return $query->where('user_id', $request->user()->getKey());
552+
})
553+
```
554+
555+
#### Formatting
556+
557+
#### Aggregates
558+
559+
#### Grouping
560+
561+
#### Subresources
562+
525563
### BelongsTo
526564

527-
The `BelongsTo` field is typically a handler for a `Illuminate\Database\Eloquent\Relations\BelongsTo` relation:
565+
The `BelongsTo` field is typically a handler for an existing `Illuminate\Database\Eloquent\Relations\BelongsTo` relation:
528566

529567
```php
530568
$field = BelongsTo::make(__('Author'), 'author');
531569
```
532570

533-
> Root assumes that there is an already defined `author` relation on the Resource Model.
571+
> The `BelongsTo` field cannot be a subresource.
534572
535573
### BelongsToMany
536574

0 commit comments

Comments
 (0)