ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

Laravel中的RouteCollection.php中的NotFoundHttpException

2019-07-05 22:29:45  阅读:375  来源: 互联网

标签:php laravel-5-4


路线文件

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/' , ['as' => '/', 'uses' => 'LoginController@getlogin']);
 Route::post('/Login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
 Route::get('/login', array('as' => 'login', 'uses' => 'LoginController@getLogin'));

 Route::group(['middleware'=>['authen','roles' ]], function(){   
    Route::get('/logout' , ['as' => 'logout' , 'uses'=> 'LoginController@getLogout']);
    Route::get('/dashboard',['as'=> 'dashboard', 'uses'=> 'DashboardController@dashboard']);
});

的LoginController

    class LoginController extends Controller{
        use AuthenticatesUsers;
        protected $username = 'username';
        protected $redirectTo = '/dashboard';
        protected $guard = 'web';

        public function getLogin()
        {`enter code here`
          if (Auth::guard('web')->check()){
            return redirect()->route('dashboard');
          }
            return view('login');
          }
         public function postLogin(Request $request)
        {
           $auth = Auth::guard('web')->attempt(['username'=>$request->username, 'password'=>$request->passwod , 'active' => 1]);

           if ($auth) {
             return redirect()->route('dashboard');
              }
            return redirect()-> route('/');
              }
         public function getLogout()
         {
            Auth::guard('web')->logout();
            return redirect()->route('/');
         }
    }

每当我尝试登录时,网址都会转到“http://localhost:8000/login
”和RouteCollection.php第179行中的NotFoundHttpException:发生错误.

我尝试了很多时间,但我无法登录Laravel.

刀片文件

 @extends('layouts.app')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">login</div>
                <div class="panel-body">
                    <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }} ">
                       {{ csrf_field() }} 

                        <div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
                            <label for="username" class="col-md-4 control-label">Username</label>

                            <div class="col-md-6">
                                <input id="email" type="username" class="form-control" name="username" value="{{ old('username') }}" required autofocus>

                                @if ($errors->has('username'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>






                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password"
                                    required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
                                    </label>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-8 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Login
                                </button>


                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

解决方法:

从表单的action属性中删除最后一个空格:

 <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }} ">

应该:

 <form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">

另外,在登录后路线中使字母L变小.

Route::post('/Login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);

应该

Route::post('/login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);

标签:php,laravel-5-4
来源: https://codeday.me/bug/20190705/1391500.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有