Reputation: 21
How to add repeatable field to add more than one phone number and address with Add Phone, Add Address option using laravel backpack?
i have 3 tables (person, phone, Address tables)
address and phone tables has relationship with person tables
i want to accept name using text field, accept phone numbers and adresses using repeatable field and save name in person table, phone numbers in phone table and adresses address table separately.
$this->crud->addField([
'name' => 'Landline',
'label' => 'Phone Numbers',
'type' => 'repeatable',
'fields' => [
[
'name' => 'Landline',
'type' => 'text',
'label' => 'Phone Number',
'wrapper' => ['class' => 'form-group col-md-12'],
],
,
],
'new_item_label' => '+Add Phone',
]);
$this->crud->addField([
'name' => 'person_addresses', // belongsTo relation
'label' => 'Adresses',
'type' => 'repeatable',
'pivot' => true,
'fields' => [
[
'label' => 'Region',
'type' => 'select',
'name' => 'region_id',
'attribute' =>'region',
'entity' => 'region',
'wrapper' => [
'class' => 'form-group col-md-4'],
],
[
'label' => 'City/Subcity',
'type' => 'select',
'name' => 'city_id',
'attribute' =>'city',
'entity' => 'city',
'allows_null' => true,
'model' => 'App\Models\city',
'wrapper' => [
'class' => 'form-group col-md-4'],
],
[
'name' => 'location_pin',
'type'=> 'address_algolia',
'label' => "Location Pin",
'wrapper' => [
'class' => 'form-group col-md-4'
],
],
],
'new_item_label' => 'Add Address',
]);
Upvotes: 1
Views: 2852
Reputation: 6193
By default the repeatable field will store that info as JSON in the database.
If you want it stored another way, I recommend you create the field using a bogus name (eg contact), then
Upvotes: 3