blackmamba
blackmamba

Reputation: 107

DELETE method is not supported for this route. Supported methods: GET, HEAD, POST

I'm using laravel 9.x my route is

Route::middleware('verified')->group(function (){
    
    Route::get('dashboard', function () {
        return view('dashboard');
    })->name('dashboard');
    
    Route::resource('kullanicilar', UserController::class);    
});

and my controller has destroy methods

public function destroy($id)
    {
        
        echo 'destroy'.$id;
        //User::find($id)->delete();
        //return redirect()->route('kullanicilar.index')
        //    ->with('success','Kullanıcı başarı ile silindi.');
        
    }

and my user_index.blade.php

<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}" style="display:inline">
   @csrf
   @method('DELETE')
   <button type="submit" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></button>
</form>

even though everything seems to comply with the rules, I'm getting this error.

enter image description here

Upvotes: 0

Views: 3986

Answers (3)

Joukhar
Joukhar

Reputation: 872

action NOT aciton in Your Form Ex :

<form method="POST" action="{{ route('kullanicilar.destroy',$user->id) }}" 
  style="display:inline">
   @csrf
   @method('DELETE')
   <button type="submit" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></button>
</form>

Upvotes: 1

blackmamba
blackmamba

Reputation: 107

I found the solution by overriding the destroy method with get on the web.php route. it's working for me for now.

such as

 //this should be at the top
Route::get('kullanicilar/remove/{id}', [UserController::class,'destroy'])->name('kullanicilar.remove'); 
Route::resource('kullanicilar', UserController::class); 

and change my user_index.blade.php

<a href="{{ route('kullanicilar.remove',$user->id) }}"  title="Sil" class="btn btn-sm btn-danger"><i class="fa fa-times"></i></a>

it works.

Upvotes: 0

Snapey
Snapey

Reputation: 4110

You have a typo in the action element causing the form to be posted back to the same route as the original page;

<form method="POST" aciton="{{ route('kullanicilar.destroy',$user->id) }}"

note action is misspelled

Also, as you are using resource controller, you should accept the model in the destroy method.

Use Route::list to check what your controller should accept

Upvotes: 1

Related Questions