Reputation: 1
I want to delete my user... by id on table users
Form :
<form action="/dashboard/crud/{{ $user->id }}" method="post" class="d-inline">
@csrf
@method('delete')
<button class="badge bg-danger border-0" onclick="return confirm ('Hapus?')"><span data-feather="x-circle"></span></button>
</form>
Route:
Route::resource('/dashboard/crud', DashboardUserController::class)->middleware('auth');
Controller
public function destroy(User $user)
{
User::destroy($user->id);
return redirect('/dashboard/crud'); with('success', 'data telah terhapus! ');
}
Did I do something wrong? Please help...
Upvotes: 0
Views: 79
Reputation: 66
The above mentioned process is correct. But in my opinion when you submit a form with POST method you should not send any value via Route/URL.
Upvotes: 0
Reputation: 1574
Your route is not correct
Route::resource('/dashboard/crud', DashboardUserController::class)->middleware('auth');
change this to
Route::post('/dashboard/crud/{user}', DashboardUserController::class)->middleware('auth');
https://laravel.com/docs/9.x/routing#required-parameters
Also delete this line @method('delete')
Upvotes: 2