HomeTech PointPHP: How to fix...

PHP: How to fix error “The POST method is not supported for this route. Supported methods: GET, HEAD” Laravel

Sometimes, you may face an issue with your edit page. When you submit, this error occurs:

How to fix error “The POST method is not supported for this route. Supported methods: GET, HEAD”

You have no idea where that originated, as you are relatively new to Laravel.

routes(web.php):

Route::group([‘middleware’ => ‘auth’], function () {

Route::get(‘/’, ‘ProjectController@index’);

Route::get(‘/projects/{id}’, ‘ProjectController@show’);

Route::post(‘/create’,’ProjectController@store’);

Route::get(‘/create’, ‘ProjectController@create’);

Route::get(‘/projects/{id}/delete’, ‘ProjectController@destroy’);

Route::put(‘/edit’,’ProjectController@update’);

Route::get(‘/projects/{id}/edit’, ‘ProjectController@edit’);

});

 

Controller:

public function edit($id)

{

return view(‘project.edit’,[

‘project’ => Project::find($id)

]);

}

/**

* Update the specified resource in storage.

*

* @param  \Illuminate\Http\Request  $request

* @param  int  $id

* @return \Illuminate\Http\Response

*/

public function update(Request $request)

{

$project = Project::find($request->id);

$project->project_name = $request->input(‘project_name’);

$project->client = $request->input(‘client’);

$project->description = $request->input(‘description’);

$project->time_span = $request->input(‘time_span’);

$project->text_report = $request->input(‘text_report’);

$project->created_by = $request->input(‘created_by’);

$project->save();

return  redirect(‘/’)->with(‘success’, ‘Project aangepast’);

}

 

There are various ways to handle this situation:

If you insist on using PUT, you can change the form action to POST and add a hidden method field with the value PUT as well as a hidden csrf field (if you’re using blade, simply add @csrf field and method field(‘PUT’) ). The form would then accept the request.

Simply update the form’s route and method to POST. Since you are the one specifying the route and not the resource group, it will function properly.

You may aware that this is not the answer to the OP’s question. However, Google indexed this site #1 when I looked for solutions to this problem. I believe that this will benefit others for this reason.

  • The subsequent error…
  • This route does not support the POST method. Methods supported: GET and HEAD.

caused by failure to delete the routing cache.

php artisan route:cache

add @method(‘PUT’) on the form

Exp:

<form action=”…” method=”POST”>

@csrf 

@method(‘PUT’)

</form>

In your situation, simply executing the command worked like a charm.

php artisan route:clear

You can change the /managers/games/id/push/ link by removing the final slash and it will start working.

$http({

method: ‘POST’,

url: “/managers/games/id/push”,

Possible cause: You haven’t yet upgraded to Laravel 5.8.

The following is how your code will appear in web.php:

Route::post(‘/edit/{id}’,’ProjectController@update’);

First, we get rid of the random parameter id so that it looks like this:

Route::post(‘/edit’,’ProjectController@update’);

Second, ditch the @method(‘PUT’) from your form; in this case, we’ll stick with the tried-and-true POST method.

But how can you send that identifier to my method?

The first thing you need to do is create a form input field and give it the hidden property.

A hidden input with the following parameters:

 input type=”hidden”, value=”$project->id”, name=”id”>

You’ll need to retrieve that ID in the update method of your controller.

$id = $request->input(‘id’);

Consequently, you cannot utilise it to determine which work needs updating.

$project = Project::find($id)

//OR

$project = Project::where(‘id’,$id);

The simple way to fix this is to add this to your form.

 

 

 

{{ csrf_field() }}

<input type=”hidden” name=”_method” value=”PUT”>

 

then the update method will be like this :

public function update(Request $request, $id)

{

$project = Project::findOrFail($id);

$project->name = $request->name;

$project->description = $request->description;

$post->save();

}

 

If you are using a Route::group, with a vendor plugin like LaravelLocalization (from MCAMARA), you need to put POST routes outside of this group. I’ve experienced problems with POST routes using this plugin and I did solved right now by putting these routes outside Route::group..

Just name your routes.

Route::post(‘/{page}/articles’, AddArticle::class)->name(‘addArticle’);

Not all of the paths need to be written out, just stick to the standard procedures. ITtutoria.net is also available to help with any problem.

We hope you will find the Solution!!!

Check out: Programming Languages For eLearning App Development

Most Popular

More from Author

Transitioning from Traditional Landlines to VoIP

In the digital age, businesses are constantly seeking ways to improve...

DJI Osmo Pocket 3 Review: The Ultimate Portable Filming Marvel

In 2020, DJI launched the Osmo Pocket 2, a notable upgrade...

6 Reasons Why You Should Get a Monsgeek keyboard With Akko Switches

Mechanical keyboards have seen a huge surge in popularity in recent...

Creating Photos for Passports is Pretty Easy with AI

Passport photos, similar to other important documents, often require images or...

Read Now

Best Way to Burn MP4 to DVD on Windows/Mac

People like to download various streaming videos online and then watch them on their mobile phones or computers. But some users prefer to enjoy videos on a large TV screen. Therefore, you can choose to download the favorite videos and convert and burn them to DVD. This...

How Audioenhancer.ai Can Make Your Audio and Video Recordings Sound Better?

Are your videos and recordings sounding less than perfect? Whether you're a content creator, a business professional, or just someone who enjoys capturing moments, the quality of your audio and video recordings can significantly impact the overall experience. Fortunately, there's a solution that can transform your mediocre audio...

Full VideoHunter Facebook Downloader Review: Download Facebook Videos in High Quality

VideoHunter, the world’s most popular video downloading solutions provider, has newly released VideoHunter Facebook Downloader to help you hunt video resources from the most widely-used social media platforms, Facebook, and grasp them as personal collections offline easily. This comprehensive review on VideoHunter Facebook Downloader will introduce this...

Common Testing Methods for PCB Assembly

Printed Circuit Board Assemblies (PCBAs) are critical components in modern electronics. They are found in almost every electronic device, from smartphones and laptops to industrial equipment and medical devices. Ensuring the functionality and reliability of these assemblies is essential. This blog post will discuss common testing methods...

How Live Chat is Driving Sales and Shaping the Future of E-Commerce

In today’s tech-savvy world, e-commerce is changing rapidly, and customer-centric strategies are now prominent. One such strategy is the integration of live chat, an underappreciated powerhouse. Connecting customers to service agents in real-time, live chats are turning into the backbone of sales in e-commerce, paving the way...

Best Amazon Music Converter Review [2023 Update]

When Amazon Music applied DRM to encrypt all its streaming music resources, there are some regulations you need to pay attention while accessing and enjoying them within the platform. So if you probably wonder if there is a way to bypass this obstacle and download Amazon to...

Evening Activities That Will Make You More Happy

Are you sick and tired of feeling down in the evening? Do you want to feel happier, more productive, and less stressed after the work day ends? If so, you should read this blog article. In these hectic times, it's important to find activities that bring us...

How to Remove DVD Copy Protection (3 Best Ways)

To combat piracy, actions have been taken to safeguard the audio and video on DVD discs, commonly referred to as DVD Copy Protection. However, these measures can also impact enjoying DVD content on smartphones, tablets, laptops, and other mobile devices from an individual perspective. If you are...

MuConvert Apple Music Converter Review: Best DRM Removal Tool

The field of music downloading and conversion is highly competitive, with the challenge of removing digital rights management (DRM) protection. Today, we will have a comprehensive review of a prominent tool for downloading Apple Music, MuConvert Apple Music Converter. Looking through, you will gain valuable insights into...

Surfshark VPN: A Great Way to Protect Your Online Presence

VPNs can increase your online anonymity by routing your web traffic through an encrypted connection to a faraway server. However, this level of security can come at a cost – in the case of Surfshark VPN, in actual dollars and cents. The Surfshark VPN is our most...

The First 8 Things You Should Always Do with Your New PC

Unboxing a new prebuilt gaming PC or your new home office desktop is like opening a treasure chest of possibilities. However, to ensure longevity, top performance, and security, some essential tasks must be addressed before you can start using your PC. Discover the first eight things you should...

The Main Differences Between Virtual Phone Numbers and SIM-card

In today's world, saturated with information and technological innovations, virtual phone numbers to receive SMS are becoming an indispensable tool for ensuring security and privacy online. This technology, seemingly insignificant at first glance, has long ago transcended purely entertainment purposes and has become an important tool in...