Laravel中的RouteCollection.php中的NotFoundHttpException

时间:2017-05-11 10:55:44

标签: 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。

Blade文件

 @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

3 个答案:

答案 0 :(得分:0)

尝试http://localhost:8000/yourProjetcName/login而不是localhost:8000 / login&#10(如果它不起作用)尝试访问http://localhost:8000/yourProjetcName/index.php/login(如果它起作用),则需要在apache vHosts文件中设置虚拟主机< / p>

答案 1 :(得分:0)

当未满足特定条件时,当尝试访问由中间件重定向到另一个URL的代理路由时,我收到此错误。我不知道如何在Laravel中处理有关API的重定向请求,但是直到在堆栈跟踪末尾检查请求对象之前,我一直在OP中出现错误。

我已经搜索了API重定向期间的具体行为,但唯一不断弹出的问题是“重定向到登录”。似乎没有人经历过端点从重定向返回响应时发生的情况。

因此,由于在中间件中解决了重定向问题,这对我来说是解决问题的方法,因此,我认为这是默认行为,并建议未来该问题的访问者检查连接到其预定路由的中间件。

回想起来,抛出错误似乎是一种逻辑响应(不要忘记NotFoundHttpException错误并不完全有助于诊断问题所在)。您被重定向到的页面可能需要诸如请求输入之类的操作,而该客户端无处可填补。在这种情况下,响应实际上是没有用的。

答案 2 :(得分:-1)

ssh通过腻子(Windows)或终端(Mac)连接到您的服务器,并按以下方式更改目录的所有权:

chown -R daemon:daemon /your/script/directory