javascript - Missing required parameters for [Route: users.update] [URI: users/{user}]

i want to update the user authenticator update information by a using jQuery ajax, but it gives me errorMissing required parameters for [Route: users.update] [URI: users / {user}]. (View: D: \ wamp \ www \ aswakt \ resources \ views \ users \ edit.blade.php)
, and I apologize because I am a beginner.
hi, i want to update the user authenticator update information by a using jQuery ajax, but it gives me errorMissing required parameters for [Route: users.update] [URI: users / {user}]. (View: D: \ wamp \ www \ aswakt \ resources \ views \ users \ edit.blade.php)
, and I apologize because I am a beginner.
edit.blade.php
<table class="table ">
<tbody>
<tr data-name='{{ $users->name }}'>
<th scope="row"> name </th>
<td>{{ $users->name }}</td>
<td><button class='btn btn-info btn-xs btn-edit'>Edit</button></td>
</tr>
<tr data-name='{{ $users->email }}'>
<th scope="row"> email </th>
<td>{{ $users->email }}</td>
<td><button class='btn btn-info btn-xs btn-edit'>Edit</button></td>
</tr>
</tbody>
</table>
jQuery
<script type="text/javascript">
$(document).on('click', '.btn-edit', function(e) {
let $btn = $(this).hide();
let $tr = $btn.closest('tr');
let name = $tr.data('name');
$tr.children("td:eq(0)").html(`<input name="edit_name" value="${name}">`);
$tr.children("td:eq(1)").prepend("<button class='btn btn-info btn-xs btn-update'>Update</button><button class='btn btn-warning btn-xs btn-cancel'>Cancel</button>")
});
$(document).on('click', '.btn-update', function(e) {
let $btn = $(this);
let $tr = $btn.closest('tr');
let name = $tr.find('[name="edit_name"]').val();
$.ajax({
type: 'POST',
url: "{{ route('users.update') }}",
data: {
'name':name,
'id':id,
"_token": "{{ csrf_token() }}"
},
success: function(data){
console.log(data);
$tr.data({ name });
$tr.children("td:eq(0)").text(name);
$tr.find(".btn-edit").show();
$tr.find(".btn-update, .btn-cancel").remove();
},
error: function(){
console.log('error');
},
});
});
$(document).on('click', '.btn-cancel', function(e) {
let $btn = $(this);
let $tr = $btn.closest('tr');
$tr.children("td:eq(0)").text(() => $tr.data('name'));
$tr.find(".btn-edit").show();
$tr.find(".btn-update, .btn-cancel").remove();
});
</script>
UsersController.php
public function update(Request $request, $id)
{
$user=User::find($id);
$user->id = Auth::user()->id;
$user->update($request->all());
session()->flash('success', 'user updated successfully !!');
return redirect('users');
}
Answer
Solution:
Try changing your AJAX URL to:{{ route('users.update', $users->id) }}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: attempt to read property "id" on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.