NileshBhise
NileshBhise

Reputation: 59

Getting route undefined error for POST after upgrade from Laravel 4.2 to 5.0

I am upgrading my app from Laravel 4.2 => 5.x I was using routes such as

Route::post('/cancelaccount',["as"=>"/cancelaccount",'uses'=>'UserController@cancelAccount']);

But when I try to load the page, I get "/cancelaccount" undefined error. I do not get this error if it's a GET request, I have problem with all my POST requests which are submitting to controller methods.

Currently as a workaround, I am replacing all actions to Controller@method format from URL format

Am I missing anything?

Upvotes: 1

Views: 109

Answers (1)

NileshBhise
NileshBhise

Reputation: 59

So after searching high and low for the answer on internet, I realized that I was looking at wrong place. I was looking at Route for an answer which is not where the problem lies.

So here's the answer if some poor soul is facing the same issue. Route undefined error will be encountered only for Form actions. In Laravel 5, Form "action" is reserved for only Controller methods. If you want to POST to named route, Open your form like this

Form::open('route'=>'your-named-route')

In my case I changed my form definition to

Form::open('route'=>'/cancelaccount','method'=>'post')

Ofcourse you can still use Form::open('action'=>'Controller@method')

Hope this helps!

Upvotes: 1

Related Questions