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

I get the following error with the code below.

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

Controller

public function destroy(Post $post)
{
    $post->delete();

    return back();
}

Route

Route::delete('/posts/{post}', [PostController::class, 'destroy']);

View

<form action="{{ route('posts', $post) }}" method="POST" >
    @csrf
    @method('delete')
    <button type="submit" class="text-blue-500">Delete</button>
</form>

Upvotes: 0

Views: 2709

Answers (2)

pragna bhudiya
pragna bhudiya

Reputation: 1

just follow the sequence for this:

@method('DELETE')
@csrf

and it works for me

Upvotes: 0

Zubair Bin Tareque
Zubair Bin Tareque

Reputation: 1

Route:

Route::delete('/admin/user_list/{id}', [UserController::class, 'destroy'])->name('admin.user_list');

Controller:

public function destroy(Request $request, $id)
{
  User::where('id', $id)->delete();
  return redirect()->back()->withSuccess('Your record deleted successfuly');

}

View:

form action="{{ route('admin.user_list', $rows->id) }}" method="post"
@method('DELETE')
@csrf

<button onclick="return confirm('Are you sure you want to delete this?');" type="submit" value="delete" class="btn btn-danger btn-xs">
    <span>DELETE</span>
</button>

Upvotes: 0

Related Questions