0

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>
Karl Hill
  • 12,937
  • 5
  • 58
  • 95

2 Answers2

0

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>
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – tomasantunes Apr 15 '22 at 09:13
0

just follow the sequence for this:

@method('DELETE')
@csrf

and it works for me

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103