File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments