Skip to content

Commit 4f2fd23

Browse files
committed
wip
1 parent 8ac006a commit 4f2fd23

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

fields.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,36 @@ $field = Boolean::make(__('Enabled'), 'enabled');
154154

155155
### Checkbox
156156

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

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

171+
You may also pass a `Closure` to customize the resolution logic of the options:
172+
173+
```php
174+
use App\Category;
175+
use Illuminate\Database\Eloquent\Model;
176+
use Illuminate\Http\Request;
177+
178+
$field = Checkbox::make(__('Categories'), 'categories')
179+
->options(static function (Request $request, Model $model): array {
180+
return match (true) {
181+
$request->user()->isAdmin() => Category::query()->pluck('name', 'id')->all(),
182+
default => $request->user()->categories()->pluck('name', 'id')->all(),
183+
};
184+
});
185+
```
186+
168187
### Color
169188

170189
### Date

0 commit comments

Comments
 (0)