Field Repeater
How to declare a Repeater Field, Repeater is available for only 1 level.
Here are the field can put inside the Repeater.
- Text
- Date
- Number
- Select
- Radio
- Checkbox
- Checkbox list
- Textarea
- Rich editor
- Hidden
use Hoggarcrud\Hoggar\Fields\Repeater;
use Hoggarcrud\Hoggar\Fields\TextInput;
$this->form([
Repeater::make('members')
->form([
TextInput::make('name')
])
->lines(2) // optional number of lines, 1 by default
->draggable(false) // optional, true by default
->addLine(false) // optional, true by default
->removeLine(false) // optional, true by default
->min(2) // optional, 0 by default
->max(2) // optional, unlimited by default
->grid(3) // optional, 1 by default
->notInDatabase() // optional, if you don't want this field in database
]);
These options are returned in JSON format. If you’re saving them using Eloquent, you should be sure to add an array cast to the model property:
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $casts = [
'members' => 'array',
];
}
How to validate the repeater files.
$request->validate([
'members.*.name' => ['required'],
],
[],
[
'members.*.name' => 'name' // 'name' will replace 'members.*.name'
]
);