简体   繁体   English

从Laravel 4.2升级到5.0后,获取POST的路由未定义错误

[英]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 我正在从Laravel 4.2升级我的应用程序=> 5.x我正在使用诸如

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

But when I try to load the page, I get "/cancelaccount" undefined error. 但是,当我尝试加载页面时,出现“ / cancelaccount”未定义错误。 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. 如果是GET请求,我不会收到此错误,我提交给控制器方法的所有POST请求都有问题。

Currently as a workaround, I am replacing all actions to Controller@method format from URL format 当前作为一种解决方法,我将所有操作从URL格式替换为Controller @ method格式

Am I missing anything? 我有什么想念的吗?

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. 在Laravel 5中,仅为Controller方法保留表格“ action”。 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') 当然,您仍然可以使用Form::open('action'=>'Controller@method')

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM