【问题标题】:Laravel 4.2 throwing MethodNotAllowedHttpExceptionLaravel 4.2 抛出 MethodNotAllowedHttpException
【发布时间】:2014-07-30 05:43:36
【问题描述】:

我有这段代码在以前的版本中有效,现在不再有效。我正在像这样进行简单的用户授权:

表格:

 {{ Form::open(array(
        'url'       => 'login',
        'method'    => 'PUT',
        'class'     => 'pure-form pure-form-stacked'
  )) }}

                    {{ $errors->first('email') }}
                    {{ $errors->first('password') }}

                    {{ Form::text('email', Input::old('email'), array('placeholder' => 'user')) }}
                    {{ Form::password('password', array('placeholder' => 'password')) }}    

                    {{ Form::submit('Log in', array('class'=>'button-primary')) }}


   {{ Form::close() }}

路线:

Route::get('login', array('https', function(){
return View::make('back-end/login');
}));

Route::post('login', array('https', function(){
$userdata = array(
        'email' => Input::get('email'),
        'password' => Input::get('password')
);

if(Auth::attempt($userdata)){
        return Redirect::to('dashboard');
    } else {
        return Redirect::to('login');
    }
}));


Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function(){
    Route::get('/', 'DashboardController@getDashboard');
    Route::resource('blog', 'BlogController');
    Route::get('logout', [
           'as'   => 'logout',
           'uses' => 'UserController@getLogout'
        ]); 
});

会加载登录页面,但是当我提交表单时,我会进入输出 MethodNotAllowedHttpException。

【问题讨论】:

  • 将方法从put更改为post

标签: php authentication laravel laravel-4


【解决方案1】:

您的登录路径是POST,但您的表单使用的是PUT。在你的Form::open 调用中将'method' => 'PUT', 切换到'method' => 'POST',(因为你不应该在那里使用PUT),它应该可以工作。

【讨论】:

  • 我这样做了,但后来我得到“404 Not Found”。
  • php artisan routes 输出什么?
  • 所有路由都存在,这没有意义,如果凭据错误,它应该重新加载登录页面而不是抛出未找到错误。
  • 尝试向我们展示php artisan routes 的输出 - 那里可能有一些其他的眼睛可能会发现的微妙之处。
猜你喜欢
  • 2013-11-14
  • 2014-09-16
  • 2016-04-23
  • 2014-11-06
  • 2015-02-02
  • 1970-01-01
  • 2019-05-15
  • 2019-03-12
  • 2018-11-25
相关资源
最近更新 更多