I want to update multiple data in database using interface form update. Form below shows the data displayed from database and will be update after enter the save button.
Below are my interface
Below are my Code
html:
<form action="" method="post"> @csrf @foreach($peoples as $people) <tr> <td> <input type="checkbox" class="name" name="name" value=""/> </td> <td> <input type="number" class="age" value="" name="age" disabled /> </td> </tr> @endforeach <button type="submit" name="button" class="btn btn-primary float-right" style="background-color: green;">Save</button> </form> Javascript/ Jquery:
<script> $(document).ready(function () { $('.name').on('change', function () { let input = $(this).closest('tr').find('input.age') input.prop("disabled", !$(this).is(':checked')); input.val(''); }); }); </script> Controller
public function update(Request $request, $id) { // $people = People::find($id); $people->age=$request->input('age'); $people->save(); return redirect('people'); } Question:
I cant updated the form to database, problem maybe related to controller.
How to set the controller for this scenario.
Thank You
https://stackoverflow.com/questions/66485572/update-multiple-rows-of-database-using-laravel-8 March 05, 2021 at 09:45AM
没有评论:
发表评论