Prevent login if user isnt approved laravel 5.4 - laravel-5

I checked all around for information about how to check on login if user is approved or not and then redirect to logged in or give an error. Now i am little confused because in internet there are a lots of posts and every one is different. So can anyone can help me to deal with this? Also it would be really nice to explain how it works (sintaxes and all other stuff)
User.php:
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'companyname', 'email', 'password', 'VAT', 'companyphone',
'companystreet', 'companycity', 'companycountry', 'companypostcode'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
LoginController :
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
login.blade.php :
#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">
#if($status = Session::get('status'))
<div class ="alert alert-info">
{{$status}}
</div>
#endif
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<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>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
#endsection
Also in my DB is boolean field "activated" default 0

#Karlis Pokkers
Middleware is one option but, I would like to go for little hack provided by Laravel documentation.
You can override Laravel's attemptLogin method.
Add this code to your app > Http > Controllers > Auth > LoginController:
/**
* Attempt to log the user into the application.
*
* #param \Illuminate\Http\Request $request
* #return bool
*/
protected function attemptLogin(Request $request)
{
return Auth::attempt(['username' => $request->username, 'password' => $request->password, 'activated' => 1 ]);
}
No need to write you own LoginController. Use Laravel's default authentication Controllers.
You can check out different sites for that. Answer on Laracast

With laravel its very simple. You have to create a new middleware or extend the app/Http/Middleware/RedirectIfAuthenticated.php middleware.
A good documentaion you can find here: https://laravel.com/docs/5.5/middleware
For example:
public function handle($request, Closure $next, $guard = null)
{
if (Auth::user()->activated) {
return redirect('/home');
}
return $next($request);
}

Related

Laravel 5.8 authentication

Hi i've a problem with laravel authentication system (5.8) The problem is that I need to login two times to enter my site
My routes file is
Route::get('/', 'RefundsController#index');
Route::get('/polizza', 'RefundsController#indexRefunds')->name('polizza');
Auth::routes();
--------------other routes------------------
RefundsController
public function __construct()
{
$this->middleware('auth');
}
public function index(){
return view('auth.login');
}
public function indexRefunds(Request $request){
DB::enableQueryLog();
$grafici = 1;
$getAverageLiquidati = DB::table('refunds')
->select(DB::raw("AVG(DATEDIFF(date_liq, date_ref)) AS avgliq"))
->where([
['disactive','=', 1],
['date_liq','<>','0000-00-00'],
['status_ref','>', 5]
])
->get();
$getAverageRifiutati = DB::table('refunds')
->select(DB::raw("AVG(DATEDIFF(date_status, date_ref)) AS avgrif"))
->where(function($q) {
$q->where('status_ref','=', 2)
->orWhere('status_ref','=', 3)
->orWhere('status_ref','=', 4);
})
->where([
['disactive','=', 1],
['date_liq','<>','0000-00-00'],
])
->get();
//dd(DB::getQueryLog());
//dd($getAverageRifiutati);
return view('pages.modify', compact('grafici','getAverageLiquidati','getAverageRifiutati'));
}
login blade
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}">
#csrf
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control #error('password') is-invalid #enderror" name="password" required autocomplete="current-password">
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
</div>
<!--<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{-- old('remember') ? 'checked' : '' --}}>
<label class="form-check-label" for="remember">
{{-- __('Remember Me') --}}
</label>
</div>
</div>
</div>-->
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
{{--#if (Route::has('password.request'))--}}
<!--<a class="btn btn-link" href="{{-- route('password.request') --}}">
{{-- __('Forgot Your Password?') --}}
</a>-->
{{--#endif--}}
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
my LoginController
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/polizza';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
}
In my Middleware
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #param string|null $guard
* #return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
return redirect('/polizza');
}
return $next($request);
}
}
When i connect to https://www.example.com/refunds/ because of definition in RefundsController it takes me to https://www.example.com/refunds/login but when i insert credentials it takes me to https://www.example.com/refunds/ with again login form then when i insert credentials it finally takes me to https://www.example.com/refunds/polizza
I dont understand why :(
The first redirect happens because in your Controller constructor, you are setting the middleware to auth. Hence, all unauthorized requests to any methods in that Controller will be redirected to default log in page. (https://www.example.com/refunds/ redirects to https://www.example.com/refunds/login)
When you enter your credentials there, Laravel takes you to your intended route (the route you tried to access without being authenticated, and that is https://www.example.com/refunds/).
This time you are authenticated, so in your controller, your index method is set to return log in view, so the view is being returned and rendered, and the form is being shown for the second time now. Now, that you log in for the second time, the Log In controller will redirect you to https://www.example.com/refunds/polizza, as there intended route does not exists, and it uses the default route which is correctly set to /polizza.
How to resolve this issue?
In your controller's constructor, change the line with:
$this->middleware('auth')->except(['index']);
This way, you will exclude the index function from the auth middleware and it can be accessible to the public. The request should no longer redirect you to the default log in page. Now, going to https://www.example.com/refunds/ will just render a log in form, as you specified in your controller. When you log in with that form, it will take you to /polizza route.

Laravel login not working properly after changing the default username and password

I have a custom table for users named 'iw_users' and inside, i have also a custom column for email and password named 'iu_email' and 'iu_password'. What i want to do here is to set my iu_email as the email and iu_password as a password on login, register, and forgot password (basically all functionalities that laravel Auth provides).
I have followed the answer on this thread: Laravel: How can i change the default Auth Password field name
But when i try to login (with correct credentials) the page is just refreshing and redirecting me again to log in page (I can confirm that laravel did not authorize me using Auth::check()).
Also, the color of the error and input are not red whenever i try to login with wrong credentials.
This is my App\User code:
class User extends Authenticatable
{
use Notifiable;
protected $table = 'iw_users';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'iu_user_id', 'iu_last_name', 'iu_first_name', 'iu_email', 'iu_mobile_no', 'iu_password', 'iu_gender', 'iu_country', 'iu_role', 'iu_photo', 'iu_status', 'iu_ipaddress'
];
public function getAuthPassword()
{
return $this->iu_password;
}
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
// Commented. i don't have 'password' and 'remember_token' in iw_users
// protected $hidden = [
// 'password', 'remember_token',
// ];
}
This is my LoginController.php
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function username()
{
return 'iu_email';
}
}
This is my login.blade.php form
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="iu_email" value="{{ old('iu_email') }}" required autofocus>
#if ($errors->has('iu_email'))
<span class="help-block">
<strong>{{ $errors->first('iu_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>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
I would suggest you to check https://scotch.io/#sukelali/how-to-create-multi-table-authentication-in-laravel
Have you got any error while debugging this? I doubt, it's unable to override their default fields.

How to store data in foreign key of a user table

The question is pretty simple. I am storing user's form data into table. I am using Auth login system of laravel, when user fill the input fields and register all values received in array called $data in create function (as you know code written in laravel as default) but when I save it in table, all values save expect department_id that is a foreign key. There is also a candidate_id and it is also a foreign key of candidate_table and it also save, but department_id have some issue.
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">Register</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
{{--<input style="text-transform: capitalize;" id="test" type="number" class="form-control" name="id" required autofocus>--}}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input style="text-transform: capitalize;" id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
#if ($errors->has('email'))
<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">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<input style="text-transform: capitalize;" id="department" type="number" class="form-control" name="department" required autofocus>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
User Model
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
public function candidate()
{
return $this->belongsTo(Candidate::class,'candidate_id');
}
public function department()
{
return $this->belongsTo(Department::class,'department_id');
}
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name','email','password','image','candidate_id'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Department;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers;
/**
* Where to redirect users after registration.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return \App\User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
// 'candidate_id' => $data['id'],
'password' => bcrypt($data['password']),
'department_id' => $data['department'],
]);
}
}
As you can see, for department_id input you have commented out form input field.
{{--<input style="text-transform: capitalize;" id="test" type="number" class="form-control" name="id" required autofocus>--}}
Uncomment the code and it will work fine.
And because of it, it will not store department_id
Try changing...
protected $fillable = [
'name','email','password','image','candidate_id'
];
to
protected $fillable = [
'name','email','password','image','candidate_id','department_id'
];

How do I retrieve POST data after Auth?

Wether I submit the login, register, or forgot password form I can't retrieve the POST data. While this is my form tag:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
It doesn't end up in /login so I'm guessing it gets redirected back to the current page. How do I retrieve this data anyway?
My goal is to know if a person has used the register/login/or forgot password form wether it failed or was successfull. (They are all on the same page in different modals)
EDIT:
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Blog;
use App\Account;
use Illuminate\Foundation\Auth;
use Illuminate\Support\Facades\Input;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
//$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$blogItems = Blog::all();
$onlinePlayers = Account::getOnlinePlayers()->count();
$onlineStaff = Account::getOnlineStaff()->count();
$input = Request('username');
return Auth::routes();
}
}
The login form:
<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="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus>
#if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</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>
<a class="btn btn-link" href="{{ url('/password/reset') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
My Routes:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Auth
Auth::routes();
//Homepage
Route::get('/', 'HomeController#index');
Route::get('/home', 'HomeController#index');
Route::get('/logout', '\App\Http\Controllers\Auth\LoginController#logout');
LoginController:
<?php
namespace App\Http\Controllers\Auth;
use \Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Auth\Authenticatable;
use Illuminate\Http\Request;
use App\Account;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Override the username method used to validate login
*
* #return string
*/
public function username()
{
return 'username';
}
}
Definitely you can. You can retrieve the login data via the following command:
If your html is:
<input type="text" name="username"/><br/>
<input type="password" name="password"/><br/>
Then inside the controller action, use the following command:
string username = Request["username"];
string password = Request["password"];

Can't retrieve posts with auth scaffold

Wether I submit the login, register, or forgot password form I can't retrieve the POST data. While this is my form tag:
<form class="form-horizontal" role="form" method="POST" action="{{ url('/login') }}">
It doesn't end up in /login so I'm guessing it gets redirected back to the current page. How do I retrieve this data anyway?
My goal is to know if a person has used the register/login/or forgot password form wether it failed or was successfull. (They are all on the same page in different modals)
My controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Blog;
use App\Account;
use Illuminate\Foundation\Auth;
use Illuminate\Support\Facades\Input;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
//$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$blogItems = Blog::all();
$onlinePlayers = Account::getOnlinePlayers()->count();
$onlineStaff = Account::getOnlineStaff()->count();
$input = Request('username');
return Auth::routes();
}
}
The login form:
<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="username" type="text" class="form-control" name="username" value="{{ old('username') }}" required autofocus>
#if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</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>
<a class="btn btn-link" href="{{ url('/password/reset') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
My Routes:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Auth
Auth::routes();
//Homepage
Route::get('/', 'HomeController#index');
Route::get('/home', 'HomeController#index');
Route::get('/logout', '\App\Http\Controllers\Auth\LoginController#logout');
LoginController:
<?php
namespace App\Http\Controllers\Auth;
use \Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Auth\Authenticatable;
use Illuminate\Http\Request;
use App\Account;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Override the username method used to validate login
*
* #return string
*/
public function username()
{
return 'username';
}
}

Resources