duanhuiqing9528 2015-09-20 04:13
浏览 56

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

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?

  • 写回答

1条回答 默认 最新

  • dsdt66064367 2015-09-20 17:50
    关注

    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!

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂