The POST method is not supported for this route. Supported methods: GET, HEAD. Laravel
There are multiple ways you can handle this:
If you insist on using
PUT
you can change the form action toPOST
and add a hiddenmethod_field
that has a valuePUT
and a hidden csrf field (if you are using blade then you just need to add@csrf_field
and{{ method_field('PUT') }}
). This way the form would accept the request.You can simply change the route and form method to
POST
. It will work just fine since you are the one defining the route and not using the resource group.
The post method is not supported for this route. Supported methods: get, head Laravel 8
Inside your form, you are using the route with the GET method instead of the route with the POST method. You are also using the function url instead of route. And instead of image-upload
it should be image.upload
with a dot .
So, you should change action="{{url('image-upload')}}"
to action="{{route('image.upload.post')}}"
This is how your form should look like:
<form action="{{route('image.upload.post')}}" enctype="multipart/form-data" method="post">
@csrf
<input type="file" name="file">
<input type="submit">
</form>
The POST method is not supported for this route. Supported methods: GET, HEAD, PUT, PATCH, DELETE. in Laravel 8
In your case, it should be {{ route('especialidades.store') }}
The reason being that default method for creating a row in db in a resource controller is App\Http\Controllers<YourResourceControllerName>@store
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
Here the create method is only for showing the form of the store method and not the function for storing the data itself.
Laravel - The POST method is not supported for this route. Supported methods: GET, HEAD
Just check your form action url route. You have to pass 'route('admin.events.add)' rather than 'route('admin.events.index')' and also dont use 'PUT' it will accept 'POST' as well.
LARAVEL 9 The PUT method is not supported for this route. Supported methods: GET, HEAD
I'd make these modifications to your code:
edit.blade:
<form action="/admin/category/update/{{$data->id}}" method="POST">
@csrf
@method('PUT')
.........
Route:
Route::put('/admin/category/update/{id}', [AdminCategoryController::class,'update'] )->name('admin_category_update');
Check if it works.
One more thing: If you correctly created model binding, your update function could look like this:
public function update(Request $request, Category $category, $id)
{
//
$category->parent_id = 1;
$category->title = $request->title;
$category->keywords = $request->keywords;
$category->description = $request->description;
$category->status = $request->status;
$category->save();
return redirect('admin/category');
}
That is because you already have the model right there: public function update(Request $request, **Category $category**, $id)
Related Topics
How to Make Number_Format() Not to Round Numbers Up
Doctrine Query Language Get Max/Latest Row Per Group
How to Alias a Table in Laravel Eloquent Queries (Or Using Query Builder)
How to Limit File Upload Type File Size in PHP
Laravel App Stopped Working After Upgrading to PHP 8
Caching Http Responses When They Are Dynamically Created by PHP
PHP Function with Unlimited Number of Parameters
Differencebetween Find(), Findorfail(), First(), Firstorfail(), Get(), List(), Toarray()
How to Create Optional Arguments in PHP
PHP Commands Out of Sync Error
Is Include()/Require() with "Side Effects" a Bad Practice
Php7.1 JSON_Encode() Float Issue
Geo-Search (Distance) in PHP/MySQL (Performance)
How to Detect a Malformed Utf-8 String in PHP
How to Check If a Url Exists in PHP