【发布时间】:2017-06-20 17:29:30
【问题描述】:
我正在尝试在 Laravel 4.2 + Sentry 中制作登录表单。问题是,当我提交表单时,我收到了不允许该方法的错误。
当我在源代码中检查我的表单时,它有method="POST",并且在我写的路径中post。可能是什么问题?
MethodNotAllowedHttpException
但不明白为什么?这是表格
{{ Form::open(array('route' => 'check-auth')) }}
<div class="body bg-gray">
{{-- Display flash message --}}
@if (Session::has('flash_message'))
<span style="margin-left:18%; color: #ff0000">{{ Session::get('flash_message') }}</span>
@endif
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="User email"/>
@if($errors->has('login_errors')) <span class="has-error">{{ $errors->first('email') }}</span> @endif
</div>
<div class="form-group">
<input type="password" name="password" class="form-control" placeholder="User password"/>
</div>
<button type="submit" name="submitbtn" class="btn bg-olive btn-block">Sign me in</button>
</div>
{{ Form::close() }}
路线
Route::post('user-login', ['as'=>'check-auth', 'uses'=>'AuthenticationController@login']);
和控制器
public function login()
{
try{
$credentials = array(
'email' => Input::get('email'),
'password' => Input::get('password')
);
$user = Sentry::authenticate($credentials, false);
if($user){
return Redirect::to('dashboard');
}
return Redirect::to('/')->with('title','Login errors');
}
catch(Exception $e){
echo $e->getMessage();
Session::flash('flash_message', 'No access!');
return Redirect::to('/')->with('title','Login errors');
}
}
更新:错误
production.ERROR: Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /var/www/html/time/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
【问题讨论】:
-
向我们展示异常可能会有所帮助。
-
@Chris 我已经更新了这个问题。这是我看到的唯一..
-
鉴于您提供的代码,我没有发现任何问题。您必须发布更多代码,正如@Chris 所说,显示整个异常。
-
您可能有,但您可以检查一下基础知识。正确的机器(我注意到错误说生产),任何嵌套到带有前缀的路由,尝试将路由重新定义为 GET 和 die(),并在控制器中路由操作的顶部使用一些消息。