mmerlijn / nova-checkboxes-field
A Laravel Nova field.
Installs: 1 075
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/nova: ^5.0
- laravel/nova-devtool: ^1.1
This package is auto-updated.
Last update: 2025-02-27 17:03:28 UTC
README
install
composer require mmerlijn/nova-checkboxes-field
Usage
use \mmerlijn\NovaCheckboxesField\Checkboxes; Checkboxes::make('Roles')->options([ 1 => 'Admin', 2=> 'Super user', ]);
config
You can customise how the values from checkbox fields are passed to your scripts. By default it's will cast all numeric keys to floats or integers, e.g. [1, 2, 3] instead of ["1", "2", "3"]. You can save disable this feature by calling withoutTypeCasting() to have the original array keys returned unmodified.
Checkboxes::make('Permissions')->options([ 1 => 'Access Admin UI', 2 => 'Manage Users', ])->withoutTypeCasting(),
Example
Checkboxes::make('users') ->options(App\User::pluck('name', 'id')) ->withoutTypeCasting(),
Give permissions to user
Add to fields
Checkboxes::make('Permissions','permissionArray') ->options(Permission::pluck('name', 'id')->toArray()) ->hideFromIndex(),
Add to User model
public function setPermissionArrayAttribute(array $value) { $this->permissions()->sync($value); } public function getPermissionArrayAttribute() { return $this->permissions->map(fn($item) => $item->pivot->permission_id)->toArray(); }
Only for developing
Make changes after nova update
cd vendor/laravel/nova && npm install