NotFoundHttpException at RouteCollection.php in Laravel

Route file

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

      

Whenever I try to login, the URL goes to " http: // localhost: 8000 / login & # 10 ;" and NotFoundHttpException on line 179 RouteCollection.php: An error occurred.

I have tried for a long time, but I cannot log into Laravel.

Blade file

 @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

      

+4


source to share


3 answers


Remove the last space from the form action attribute:

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

      

it should be:

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

      



In addition, if sent by mail, type the letter of L .

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

      

Should be

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

      

+2


source


try http: // localhost: 8000 / yourProjetcName / login instead of localhost: 8000 / login & # 10 if it doesn't work Try to access http: // localhost: 8000 / yourProjetcName / index.php / login if it works, then you need to configure a virtual host in your Apache vHosts file



0


source


ssh

to your server via putty (Windows) or terminal (Mac) and change the owner of the directory like this:

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

-1


source







All Articles