Laravel Authentication With Two Tables
Actually the solution is fantastically simple. You just need to override the getAuthPassword
method which is defined in the Authenticatable
trait, by adding this to your User
model:
public function getAuthPassword(){ return \DB::table('auth')->where('user_id', $this->id)->pluck('password');}
And that's it, now the authentication system will get the password from the auth
table before checking if it matches with user input.
You can authenticate user manually.
- Retrieve user from your
user
table by email with his password fromauth
table (via simple join or eloquent relations). - Validate that password is correct using
\Hash::check($password, $hashedPassword);
. - Login user manually using
Auth::login($user);
if you are using Eloquent orAuth::loginUsingId($id);
if simple DB query.
Docs: