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

Gamification in eLearning: Enhancing Engagement with iSpring

In today's fast-paced world, organizations rely on eLearning to train and...

Shield Your Identity with Virtual Numbers for Secure SMS Verification

Keeping your personal contact information secure has become more important than...

Building Bespoke Video Experiences with Video API

In a digital age dominated by a constant flow of content...

The Evolution of Ergonomics: A Historical Perspective on Office Chairs

The humble office chair, a staple in workplaces worldwide, has undergone...

Read Now

Elevate Your PTE Prep: The Power of Online Coaching Unleashed

Are you planning to take the Pearson Test of English Academic, too? Well, now, preparing for the PTE exam is hard work. It often takes weeks and months of intense practice to prepare for the big day. Do you think you are spending all that preparation time wisely?...

SwifDoo PDF: A Promising Premium PDF Editor

There is a set of PDF editors created and dedicated to various systems and hardware platforms with the aim of simplifying and increasing the efficiency of PDF-related processing work. Used for both commercial purposes, for corporate users and non-commercial ones. Currently existing commercial PDF programs are characterized by...

Behind the Height: Understanding the Benefits of Vertical Radiators

When it comes to home heating solutions, there's a whole world of choices giving you the flexibility to fit your design aesthetic while still getting optimal heat distribution. One option that's gaining popularity is the use of vertical radiators. These radiators, rising up rather than stretching across...

Tech Innovations in the Wellness Industry: Streamlining Your Massage Business

Technology has emerged as a key player in the ever-changing wellness market for massage enterprises.  Having a smooth appointment system accessible via user-friendly applications, that is able to tailor client experiences based on data insights, and streamlines all practice operations with effective management tools cannot be overemphasized. The...

4 Essential Tools for Effective Digital Product Development

In today's fast-paced digital world, companies must always improve their products and come up with new ideas to stay ahead of the competition. Digital product development is now a big part of having a business that does well. As technology has gotten better, making products digitally has...

How do Smart Home Gadgets Work?

People are shifting more and more toward smart home solutions by every passing day. These indispensable gadgets simplify tasks for users, providing them convenience and peace of mind. From smart security systems to smart home assistants, all of these devices contribute to helping reshape the meaning of a...

Securing Your Purchase: How to Track eBay Packages Effectively

Understanding Package Tracking on eBay When you make a purchase on eBay, it's crucial to keep an eye on your shipment. The ability to track eBay package offers peace of mind and ensures you're fully informed about the status of your order. Tracking isn't just a convenience; it's...

Diving into CapCut’s Online Photo Editor: Mastering Color Correction Techniques

CapCut’s online photo editor stands as a versatile toolkit for enhancing and refining images. Among its array of sophisticated features, the repertoire of color correction techniques serves as a cornerstone in the pursuit of visual perfection. This robust toolset not only allows users to perfect color balance...

Game On: Navigating the Playfield of Mobile Game Monetization Trends

In the dynamic world of mobile gaming, keeping pace with evolving trends is crucial to unlocking the full potential of your game's profitability. As the playfield of monetization continues to transform, developers need to navigate through the latest trends to ensure success. Let's explore the cutting-edge strategies that...

How to Remove Snapchat AI with or without Snapchat+

As a popular social media platform and a pioneer in fleeting message platforms, Snapchat recently launched a cutting-edge AI feature called 'My AI'. While many users appreciate and enjoy the personalized touch this AI adds to their experience, some still feel invasive or even find it creepy....

Exploring Different Monetization Models: Finding the Right Fit for Your App

Just as the mobile app industry has grown, the ways of monetizing apps have grown in recent years. There are more ways than ever to make money with apps thanks to a variety of monetization models. The catch is that not every monetization model is going to...

How to React to Instagram Messages

Instagram has become one of the most popular social media platforms for connecting with friends, family, and brands. With its massive user base, chances are you receive Instagram direct messages (DMs) regularly. Knowing how to respond thoughtfully keeps conversations going. At Pumpic, we gathered everything you need...