Basics
The FieldsGroup component is designed for the quick grouping of a set of fields, filling them with data, and changing their states.
You can create a FieldsGroup by using the static method make()
of the FieldsGroup
class.
make(iterable $components = [])
$components
- a set of FieldContract.
use MoonShine\UI\Components\FieldsGroup; FieldsGroup::make([ Text::make('Title'), Email::make('Email'),]);
Filling with data
To fill all fields with data, use the fill()
method:
fill(array $raw = [], ?DataWrapperContract $casted = null, int $index = 0)
FieldsGroup::make($fields)->fill($data);
Preview mode
You can switch all fields in the set to preview mode using the previewMode()
method:
FieldsGroup::make($fields)->previewMode();
Without wrappers mode
You can switch all fields in the set to without wrappers mode using the withoutWrappers()
method:
Wrappers - fields that implement the FieldsWrapperContract interface, for example, StackFields.
Therefore, when using the withoutWrappers
method, all nested fields will be extracted from the wrapper field,
and the wrapper field itself will not be included in the final set.
FieldsGroup::make($fields)->withoutWrappers();
Mass field modification
All the methods described above use the mapFields
method under the hood, which allows you to iterate through all elements in the set and change their state:
FieldsGroup::make($fields)->mapFields(fn(FieldContract $field, int $index): FieldContract => $field);