LARAVEL - INPUT ERROR - The POST method is not supported for this route. Supported methods: GET, HEAD - laravel

I'm trying to create an input form but couldn't find the solution from the error
This is what it said
My View Code
My Controller
My Router
I've tried some tips online but it still won't work

It's because your route name is not defined. you should add the route name like this
Route::post('CreateItem', 'CreateItem#insert')->name('CreateItem');

I think is related to the route name. Have you check which uri is posting the form? Can you try:
Route::post('/createItem', function () {
//
})->name('createItem');

Sorry, got the answer
Route::post('CreateItem','CreateItem#insert');
to
Route::post('/create_item','CreateItem#insert');
and
class CreateItem extends Controller
in my question, I typed the wrong controller name, it should be CreateItem
Thanks for the effort to answer my question tho..

Related

Get Controller name and Method in laravel

I have to get my controller and method name from route, for example:
Route::get('/', 'HomeController#index')->name('home');
I have to get:
HomeController#index
Also, I have to get name of the action of my route(like POST and GET) automatically from my controller as well.
EDIT:
https://www.nicesnippets.com/blog/how-to-get-current-route-name-path-and-action-in-laravel-6
Thanks to this website, now I can get the method and controller from routes, the remaining thing that I still dont found is to how to get the action(ex:POST or GET) from my route
Does anyone have any suggestions?
You are looking for request()->route()->getActionName();

What is the difference between those routes?

I define route for update profile logic, when I used first logic It does not work but the use of second logic works fine. So I don't know what is the difference between those.
1. Route::post('/profile', 'ProfileController#update');
2. Route::post('/profile', 'ProfileController#update')->name('profile');
The only difference between them, the name,
so If you put in form action something like {{ route('profile') }} you mean: go to route that has name profile.
Read this for more details.
Routes with name eg Route::post('/profile', 'ProfileController#update')->name('profile');
can be accessed in blade using {{route('profile')}}
whereas the other one can only be accessed using url(). e.g
{{url('/profile')}}
The second one is a 'named route'. It allows you to reference your route by a name.
Laravel 5.7 Docs - Routing - Named Routes
Well the obvious difference is the added "->name('profile')" named route to your second line. You have tagged this post with laravel-5.7 so I have linked the documentation for this version: https://laravel.com/docs/5.7/routing#named-routes
It appears to me that perhaps you have some logic in the update function of your ProfileController like so:
if ($request->route()->named('profile')) {
//
}
Which would change the outcome of the request. Hope this helps, best regards.

Laravel trouble routing to update Controller

I'm trying to edit a Alumne model with a model Form but I only have a NotFoundHttpException
The application only fails when I confirm the edit form. I think the problem is in the Form::model line but don't know.
Here's the entire code:
http://laravel.io/bin/62eq
Thanks.
All looks correct...
Check if $alumne really has id or is named different like alumne_id or id_alumne... Is the only thing may be.

How do I redirect or call a different Controller Action from my Controller Action in Magento?

I want to call cms/index/noRoute Action from one of my custom module's controller action, How do I do it?
I tried,
$this->_redirectUrl('cms/index/noRoute')
and
$this->_forward('cms/index/noRoute')
also few variations for redirect URL like '*/cms/index/noRoute' etc, non of them worked. How should I do this?
Use below code :
$this->_redirect('defaultNoRoute');
return;
its work for me.
Found it, and its so simple,
$this->norouteAction();
Since I'm doing this in one of my controllers which is extended from Mage_Core_Controller_Front_Action which is again extends from Mage_Core_Controller_Varien_Action, gives me the ability to call norouteAction().
I think this should do the trick (untested): $this->_redirectUrl($this->getUrl('cms/index/noRoute'))

MVC Routing Engine routes same formatted route to different controller actions

Okay, I did my homework and search SO, and indeed I found similar questions but not reporting the behavior I'm getting.
Here is the deal, I have defined a route:
routes.MapRoute("CategoryName", "Category/Name/{text}",
new { controller = "Category", action = "Name", text = "" });
The twist here is the following:
This url: http://www.url.com/Category/Name/existingCategoryName
And this url: http://www.url.com/Category/Name/anotherExistingCategoryName
Both url's should go to the same controller method which is public ActionResult Name(string text) but sadly the first url is going to the default Index method, the second is being routed correctly.
I wonder why this happens, as I've been with .net mvc for several years and never experienced this behavior.
As a side note here are some facts:
As it's being route to different methods, I doubt the code inside them has something to do with it.
When manually write the category to something it doesn't exists in the DB as a category name it goes through the Name method.
The routes are placed correctly, as I'm aware the first route that matches the pattern will win.
Even I tried place the CategoryName route first, the behavior is the same.
When writing each link in the Category/Index I use the same #Html.RouteLink() helper, so all the links are formatted the same way.
Thanks in advance!
Are you using the - sign in the failing route?
Maybe you can find more information with the Routing debugger
And maybe you can look at this question: Failing ASP.NET MVC route. Is this a bug or corner case?
Phil Haack also give an possible answer to your problem in: ASP.NET routing: Literal sub-segment between tokens, and route values with a character from the literal sub-segment

Resources