PHP: 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 “PHP: 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

Recent Posts

How to Trade in Path of Exile 2: A Beginner’s Guide

Trading is a fundamental aspect of Path of Exile 2, enhancing your gaming experience by allowing you to acquire desired items and currency. This...

Mastering PoE Trade: A Comprehensive Guide to Trading Success

Trading in Path of Exile (PoE) can be overwhelming for new players, especially without an official auction house. With a player-driven marketplace, PoE requires...

Travis Touch Plus Voice Translator Device: User Manual

Introduction In today’s interconnected world, breaking down language barriers is essential. The Travis Touch Plus Voice Translator is an advanced portable device designed to...

MUAMA Enence Voice Translator: Complete User Manual

In today’s globalized world, the ability to communicate across language barriers is more essential than ever. The MUAMA Enence Voice Translator has emerged as...

Seven Easy Fixes To Protect Your Android phone Privacy

As Android phones become more integrated into our daily routines, they store an increasing amount of personal information, making privacy concerns a significant issue....

Your Mobile Phone Ringtones Influence On Others

Mobile phone ringtones are often more than just notifications. They have the power to shape our social interactions, public image, and overall environment. What...

Best Flagship Smartphones of 2025: A Comprehensive Guide

The smartphone market is expected to reach new heights in 2025. With cutting-edge technology, stunning displays, and improved AI systems, the best flagship smartphones...

More from Author

Read Now

The 6 Best Gaming Laptops to Buy

Gaming laptops provide powerful performance, portability, and versatility. Whether you’re a casual gamer or a professional eSports competitor, choosing the right gaming laptops to buy can make a world of difference. In this article, we will explore six of the top gaming laptops available today, detailing their...

What is Deepfake? What is It and How does It Work?

What is Deepfake? Deepfake uses artificial intelligence (AI) to manipulate media—images, videos, or audio—to make them appear real, though they are entirely fabricated. The term combines "deep learning" and "fake," highlighting the AI techniques used to create such content. This technology has rapidly advanced, making it increasingly...

Impacts of Quantum Cybersecurity on Digital Protection

Quantum computing is transforming data processing, creating both opportunities and risks for cybersecurity. The Quantum Cybersecurity Impact describes how quantum technologies could both strengthen and challenge existing cybersecurity frameworks. This article delves into the implications of quantum computing on digital security, exploring its potential threats and examining...

How MDM plays a vital role in Healthcare Technology?

In the ever-evolving healthcare sector, accurate data management is more critical than ever. With the increase in digital health systems, the need for robust systems to manage and streamline data has led to the widespread adoption of Master Data Management (MDM). MDM in healthcare technology ensures that...

Revolutionizing Security: The Role of Identity Verification with AI in Modern Systems

Identity verification with AI is changing the way organizations authenticate individuals. Traditional methods of verification, such as passwords or security questions, are increasingly vulnerable to hacking and fraud. AI-powered solutions use advanced algorithms, biometric data, and machine learning models. These technologies offer higher security and efficiency. AI...

Website Speed Optimization: Tools and Techniques

Website speed optimization refers to the process of improving the load time of a website. A fast website ensures that users have a smooth experience, increasing engagement and retention. Speed optimization involves technical improvements and tools that help your website load faster, improving both user experience and...

Top Integral Mobile Apps for Productivity

In today’s fast-paced world, mobile apps play a critical role in how we live, work, and connect with others. Among the vast array of apps available, some are considered essential tools, or integral mobile apps, for both productivity and entertainment. These apps seamlessly integrate into our daily...

Empowering Women in the Shipping Industry

The shipping industry has been traditionally male-dominated, but women are gradually making their presence felt. While progress has been made, the industry still faces significant challenges when it comes to gender equality. Women bring diverse perspectives and fresh ideas, which are essential for growth and innovation. For...

How to Protect SaaS Data Security Effectively?

As the adoption of Software-as-a-Service (SaaS) solutions grows, so does the need for robust data security measures. SaaS platforms often store sensitive data such as customer information, financial records, and intellectual property. Ensuring the safety of this data is critical for maintaining customer trust, complying with regulations,...

How to Scale Your SaaS Business: Tips from Industry Experts

Scaling a Software-as-a-Service (SaaS) business is a challenging yet rewarding journey. It requires not only a deep understanding of your market and product but also strategic planning and the implementation of efficient systems. Whether you're a startup or an established SaaS company, the principles of scaling are...

SaaS Customer Success: Best Practices for Retention and Growth

In today’s fast-paced Software-as-a-Service (SaaS) environment, customer success is more than just a support function. It is a vital strategy for retaining customers, ensuring satisfaction, and driving growth. SaaS companies that prioritize customer success are able to foster long-term relationships with their customers, reducing churn while expanding...

Discord App: How To Solve The Discord Login Problem on Mobile Phones and Different Browsers

If the Discord App has been causing login issues for you, you're not alone. Many users struggle to access their accounts. If you’ve been experiencing login issues with the Discord App, you’re not alone. Many users face difficulties when trying to access their accounts. Luckily, most login...