【问题标题】:POST Route, generates MethodNotAllowedHttpException when calling GETPOST Route,调用GET时产生MethodNotAllowedHttpException
【发布时间】:2014-08-14 13:14:58
【问题描述】:

我已经声明了一个 POST ROUTE:

Route::post('sessions', [
'as' => 'sessions.store',
'uses' => 'UserAuthenticationController@store'
]);

当我访问 www.domainname.com/sessions 时,它会生成 MethodNotAllowedHttpException。

我正在尝试使用以下方法处理所有丢失的路线:

/global.php/

App::missing(function($exception) {
return View::make('exceptions.404');
});

当我没有为(会话)声明任何 GET ROUTE 时,我无法弄清楚为什么会生成此异常。

谢谢

【问题讨论】:

    标签: php laravel laravel-4 laravel-routing


    【解决方案1】:

    因为您的应用程序中有debug = true

    当你的应用调试设置为false时,会显示404页面。

    【讨论】:

    • 如果我调用另一条未声明的路由将我发送到 404 页面,我认为它不会因为 DEBUG = true 而出现该错误。虽然我没有声明 GET Route 它应该由 APP::missing
    【解决方案2】:

    也许你的问题出在你的控制器上

    class UserAuthenticationController extends Controller
    {
    
    public function store()
    {
    return View::make('sessions.store');
    }
    
    }
    

    别忘了它只在您发布时有效;你也可以使用

    Route::any('sessions', [
    'as' => 'sessions.store',
    'uses' => 'UserAuthenticationController@store'
    ]);
    

    确保在会话文件夹中的视图中,stroe 文件名正确,如

    store.blade.php

    【讨论】:

      猜你喜欢
      • 2016-05-23
      • 2018-10-01
      • 2021-11-25
      • 2019-12-01
      • 2016-11-24
      • 2015-01-17
      • 2019-06-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多