Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alex_D's avatar

@method('PUT') does not work

Hi,

I am following a Laravel tutorial and I got stuck at the point, when I try to update the database entry.

The data are brought into the form and after editing sent back. Here I use "POST" method with @method('PUT') directive. and in routes I also have Route::put(' ' etc.).

I get error message that says "method is not supported for route PUT. Supported methods: GET, HEAD."

At this point I am clueless what to do. I even tried to put GET instead of POST. i get no error bu the code does not work. e.g. nothing gets updated.

Any help is highly appreciated.

0 likes
17 replies
tykus's avatar

Show the relevant form markup and Routes file.

Alex_D's avatar

Here is the code. I removed some fields for the sake of clarity.

<form method="POST" action="/listings/{{$listing->id}}" enctype="multipart/form-data">
@csrf 
@method('PUT')
<input type="text"  name="name" value="{{$listing->name}}"/>
@error('name')
<p class="text-red-500 text-xs mt-1">{{$message}}</p>
@enderror
<button class="bg-laravel text-white rounded py-2 px-4 hover:bg-black">Update</button>
</form>

and the route

Route::put('/listing/{listing}', [ListingController::class, 'update']);

and the update function from controller:

//Update Listing Data
     public function update(Request $request, Listing $listing){      
        $formFields = $request->validate([
            'name' => 'required'
        ]);
        $listing->update($formFields);
   return back()->with('message', 'Listing updated succesfully!');
    }

Analogous form with the controller

Route::post('/listings', [ListingController::class, 'store'])

and "store" function works fine

public function store(Request $request){
          $formFields = $request->validate([
            'name' => 'required'
        ]);
Listing::create($formFields);     
        return redirect('/')->with('message', 'Listing created succesfully!');
    }```
tykus's avatar

@Alex_D I suspect your problem is with the form action; you probably are passing null where the Listing identifier is meant to be. Can you confirm that $listing->id actually has a value

Alex_D's avatar

@tykus Yes, listing ID has value. I checked it by showing {{$listing->id}} in my html body

Sinnbeck's avatar

Please format your code by adding ``` before and after it

Alex_D's avatar

clearing the cache didn't help. message says

The listings/19 method is not supported for route PUT. Supported methods: GET, HEAD.

19 is my listing id

jlrdw's avatar

@Alex_D does just posting work and changing the route to post.

Don't cache routing in development.

Sinnbeck's avatar

How are you running laravel? Php artisan serve?

tykus's avatar

@alex_d the Route URL should be listings/{listing}

Route::put('/listings/{listing}', [ListingController::class, 'update']);

You have /listing/{listing}

2 likes
Alex_D's avatar

@tykus That helped Thanks all for help. And sorry for taking your time with such mistake

tykus's avatar

@Alex_D no worries, mark the thread closed if you're all set

1 like
tykus's avatar

@Alex_D that's your job :D - pick the solution as best answer above!

Please or to participate in this conversation.