This is the code for storing an array only. What I want now is to update each field or can add new rows but I don’t know how.
foreach ($request->requirements as $key => $requirements) {
$req = new FormReq();
$req->requirements = $requirements['title'];
$req->form_id = $id;
$req->save();
}
My blade file
@foreach ($requirements as $reqs)
<tr>
<td><input type="text" name="requirements[0][title]"
placeholder="Enter requirements" class="form-control"
value="{{ $reqs->requirements }}" />
</td>
<td><button type="button" class="btn btn-sm btn-danger remove-tr">Remove</button>
</td>
</tr>
@endforeach
2
Answers
Credit to Yannick's answer I was able to handle the create and update in Edit page, but I added some codes in blade in order for this to work.
I added this code to the script as well
I added key to create unique fields
First add an input hidden in your existing items. Adapt the name of the input if this doesn’t work
Then check for the presence of the id in your method