Downloads
Stars
Version
Contains a new Laravel Nova field for building collapsible radios for parent and child relationships.
You can install the package via composer:
composer require creode/collapsible-radios
To create an instance of a new field just use the CollapsibleRadios
class in your Nova resource's fields
method. You need to ensure that your options provide the following fields:
label
- The label to display for the optionvalue
- The value to use for the optionid
- The ID of the optionparent_id
- The ID of the parent optionThese fields are used to build the collapsible radios based on parent_ids.
Here is a basic example for how we would accept input for options.
use Creode\CollapseRadios\Field\CollapsibleRadios;
CollapsibleRadios::make('Model', 'model_id')
->options([
[
'label' => 'Option 1',
'value' => 1,
'id' => 1,
'parent_id' => null,
],
[
'label' => 'Option 2',
'value' => 2,
'id' => 2,
'parent_id' => 1,
],
[
'label' => 'Option 3',
'value' => 3,
'id' => 3,
'parent_id' => 2,
]
])
->nullable()
->rules('required')
This would generate a structure like the following:
or if you want to easily map model data to it:
use Creode\CollapseRadios\Field\CollapsibleRadios;
CollapsibleRadios::make('Model', 'model_id')
->options(
Model::all()->map(
function ($model) {
return [
'label' => $model->name,
'value' => $model->id,
'id' => $model->id,
'parent_id' => $model->parent_id ?: null,
];
}
)
)
->nullable()
->rules('required')
We plan to implement the following features as our requirements develop for this project:
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.