I'm sure its a quick fix but I have been through this code trying things and I am not sure what is going on. On the destroy method, Its pulling the first ID in the table regardless of what I do.
blade view
<table class="table table-striped table-hovered">
<thead>
<<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Roles</th>
<th>Actions</th>
</thead>
<tbody>
@foreach($users as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{implode(',',$user->roles()->get()->pluck('name')->toArray())}}</td>
<td>
<a href="{{route('admin.users.edit',$user->id)}}"><i class="bi bi-pencil-square fw-bold text-info"></i></a>
<a href="#" data-bs-toggle="modal" data-bs-target="#exampleModal"><i class="bi bi-trash fw-bold text-danger"></i></a>
</td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Delete User</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h6>Are You Sure You Want To Delete This User?</h6>
<form action="{{ route('admin.users.destroy',$user->id) }}" method="POST">
@csrf
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Yes, Delete</button>
</div>
</form>
</div>
</div>
</div>
@endforeach
</tbody>
</table>
route
Route::prefix('admin')->name('admin.')->group(function(){
Route::post('/delete/{id}',[UsersController::class,'destroy'])->name('users.destroy');
});
controller
public function destroy(Request $request, $id)
{
$user = User::findOrFail($id);
$user->roles()->detach();
$user->delete();
toastr()->success('User has been delete successfully');
return redirect()->route('admin.users.index');
}