php - Laravel delete method not allowed


I am writing a laravel api and when I try to make delete and post requests I keep getting a method not allowed exception. Where should I be looking to diagnose this problem?

I have read though most of the other posts on this issue and here is what I have tried/looked at. • Made sure the route syntax was correct

• Made sure it didn't conflict with another route

• Made sure I was using the correct route (ran php artisan route:list to double check)

• Modified the .htaccess folder (maybe I did this incorrectly) to allow GET, POST, PUT, DELETE

Here is what the route looks like in api.php

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
Route::delete('delete/{id}', '[email protected]');
Route::get('stuff', '[email protected]');
Route::get('stuff1/{Username}', '[email protected]');

here is the function in the controller

 public function delete(Request $request, $id) {

        $user = Login::find($id);
        return "204";

here is my .htaccess

   <IfModule mod_rewrite.c>
   <IfModule mod_negotiation.c>
       Options -MultiViews

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

 Allow from all

I can get around this issue by changing Route::delete() to Route::get() and achieve the same functionality but this doesn't seem like standard practice.




You have to set ajax type POST but send a parameter named _method with value delete like this:

        type: "POST",
        url: productRoute,
        headers: { 'X-CSRF-TOKEN' : productToken }

Or because you use laravel html form helper so it generates _method hidden input automatically so you'd better send all your form inputs such as token and method like this:


    var formData=$('#yourForm').serialize();
        type: "POST",
        url: productRoute,

People are also looking for solutions to the problem: php - WordPress 'post_name' in posts table duplicated


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.