Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Nov 18, 2024
1 parent 8ac006a commit 4f2fd23
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions fields.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,36 @@ $field = Boolean::make(__('Enabled'), 'enabled');

### Checkbox

The `Checkbox` field is typically a handler for (array of values) `json` model attributes:
The `Checkbox` field is typically a handler for `json` model attributes (array of values):

> Don't forget to [cast](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) you model attribute as a `json` or `array`.
```php
$field = Checkbox::make(__('Permissions'), 'permissions')
->options([
//
'view' => 'view',
'create' => 'Create',
'update' => 'Update',
'delete' => 'Delete',
]);
```

You may also pass a `Closure` to customize the resolution logic of the options:

```php
use App\Category;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

$field = Checkbox::make(__('Categories'), 'categories')
->options(static function (Request $request, Model $model): array {
return match (true) {
$request->user()->isAdmin() => Category::query()->pluck('name', 'id')->all(),
default => $request->user()->categories()->pluck('name', 'id')->all(),
};
});
```

### Color

### Date
Expand Down

0 comments on commit 4f2fd23

Please sign in to comment.