Reputation: 485
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 then the url goes to "http://localhost:8000/login " and NotFoundHttpException in RouteCollection.php line 179: error happen.
I tried lots of time but I can't log into Laravel.
The 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
Upvotes: 4
Views: 28244
Reputation: 441
I received this error when attempting to access an API route proxied by a middleware redirecting to another url when a certain condition was unmet. I don't know how redirect requests are handled in respect to APIs in Laravel, but I kept getting the error in the OP until I inspected the request object at the end of the stack trace.
I've googled for the specific behavior during API redirects but the only questions that keep popping up is something along the lines of "redirect to login". Nobody seems to have ever experienced what happens when an endpoint returns the response from a redirect.
So, since fixing the redirect in the middleware solved it for me, I'll assume this is the default behavior, and advise future visitors to this question to check the middlewares attached to their intended route.
In retrospect, throwing an error seems like a logical response (nevermind the NotFoundHttpException error not exactly being helpful in diagnosing what went wrong). The page you are being redirected to may require action such as requesting input, which client is in no position to fill. In such case, the response really is of no use.
Upvotes: 0
Reputation: 1029
try http://localhost:8000/yourProjetcName/login instead of localhost:8000/login
 if it does not work Try to access http://localhost:8000/yourProjetcName/index.php/login If it works, then you need to set up a virtual Host in your apache vHosts file
Upvotes: 0
Reputation: 1
ssh
to your server via putty (Windows) or terminal (Mac) and change ownership of the directory like so:
chown -R daemon:daemon /your/script/directory
Upvotes: -1
Reputation: 4114
Remove the last space from the action attribute of the form:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }} ">
should be:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
Also, make letter L small in login post route.
Route::post('/Login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
Should be
Route::post('/login', ['as'=> 'Login' , 'uses' => 'LoginController@postLogin' ]);
Upvotes: 2