I have the following database:
id | name | age |
-----------------
1 | John | 20 |
2 | Jack | 29 |
I want to edit them all in a single form with the ability to "Add more" and then save/update as needed. How is that achievable with Laravel?
My form currently is this:
@foreach($people as $person)
<input type="text" name="name[]" class="form-control" value="{{ $person->name }}">
<input type="text" name="age[]" class="form-control" value="{{ $person->age }}">
@endforeach
Then in Laravel I receive the $request->all() as follows:
"name" => array:2 [▼
0 => "John"
1 => "Jack"
]
"name" => array:2 [▼
0 => "20"
1 => "29"
]
Which I guess is expected, but not convenient to work with Eloquent. What would be the Eloquent/Laravel way of doing this?
Note: In the real world example I'm developing Name is unique.
Using Laravel 7.