The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST. in laravel 7'

Viewed 180

I am trying to use Resource Controller and having a problem with destroying method, can't find a solution.

I get this error

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

web.php

Route::resource('honor', 'HonorController');

HonorController.php

public function destroy(Honor $honor)
{
    dd($honor);
    $honor->delete();
    return redirect()->back();
}

blade

<form action="{{ route('honor.destroy', $honor->id) }}" method="post">
    @csrf
    @method('DELETE')
    <div class="btn-group">
        <a href="{{ route('honor.edit', $honor->id) }}" class="btn btn-info btn-sm">Edit</a>
        <button type="submit" class="btn btn-danger btn-sm">Delete</button>
    </div>
</form>
1 Answers

Try changing the key (uses honor, not id) to match the name of the parameter in the route.

For example:

<form action="{{ route('honor.destroy', ['honor' => $honor->id]) }}" method="post">
@csrf
@method('DELETE')
<div class="btn-group">
    <a href="{{ route('honor.edit', ['honor' => $honor->id]) }}" class="btn btn-info btn-sm">Edit</a>
    <button type="submit" class="btn btn-danger btn-sm">Delete</button>
</div>
</form>
Related