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

Time:04-10

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" ><i ></i></button>
</form>

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

enter image description here

CodePudding user response:

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

CodePudding user response:

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" ><i ></i></button>
</form>

CodePudding user response:

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" ><i ></i></a>

it works.

  • Related