dongshuzui0335
2017-08-14 12:05
浏览 35
已采纳

从网络路线上的laravel 5.4中不能使用post方法

POST method not working in laravel 5.4 , GET method is working same controller.

 Route::get('/route','PostController@custon_function'); //working

 Route::post('/route','PostController@custon_function'); //throw error

enter image description here

图片转代码服务由CSDN问答提供 功能建议

POST方法在laravel 5.4中不起作用,GET方法使用相同的控制器。 < pre> Route :: get('/ route','PostController @ custon_function'); // working Route :: post('/ route','PostController @ custon_function'); //抛出错误

< img src =“https://i.stack.imgur.com/09KgS.png”alt =“在此处输入图像说明”>

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doubi12138 2017-08-14 12:16
    已采纳

    Option 1

    You can combine GET and POST method with one route this way:

    Route::match(array('GET','POST'),'/route','PostController@custom_function');
    

    Option 2

    Or you can use this alternative:

    Route::any('/route', 'PostController@custom_function');
    

    And within controller/function, you can check method name this way:

    if (Request::isMethod('post'))
    {
    // ... this is POST method
    }
    if (Request::isMethod('get'))
    {
    // ... this is GET method
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题