douqi1625 2017-02-03 10:56
浏览 57
已采纳

看不出为什么错误是MethodNotAllowedHttpException

I'm trying to make login form in Laravel 4.2 + Sentry . The problem is that when I submit the form I got the error that method is not allowed.

When I check my form in source it has method="POST" and also in the route I've wrote post. What can be the problem?

MethodNotAllowedHttpException

but can't see why? This is the form

        {{ 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

Route::post('user-login', ['as'=>'check-auth', 'uses'=>'AuthenticationController@login']);

and controller

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');
    }
}

UPDATE: Error

production.ERROR: Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /var/www/html/time/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
  • 写回答

3条回答 默认 最新

  • douhuireng4407 2017-02-03 11:27
    关注

    You're route is correct, the only thing I could suggest would be to append the type to the opening of the form:
    {{ Form::open(['url' => 'check-auth', 'method' => 'post']) }}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c