Laravel Authentication With Two Tables Laravel Authentication With Two Tables laravel laravel

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.

  1. Retrieve user from your user table by email with his password fromauth table (via simple join or eloquent relations).
  2. Validate that password is correct using \Hash::check($password, $hashedPassword); .
  3. Login user manually usingAuth::login($user); if you are using Eloquent or Auth::loginUsingId($id); if simple DB query.

Docs: