Laravel login using id from different database

#1

Hi All,
I am trying to login using different database where I have already setup the config/database.php as well as .env files. Now how shall I write functions or login using LoginController? PLease anybody can help me.

#2

Can anyone help me with this as I have seen many forums but not getting how to start. Any help would be great.

#3

You mean, you want to run queries against two different database in the same processes?

#4
#5

public function LegonSignin(Request $input) {

    $rules = $this->validate($input, [
        'tgi' => 'required',
        'password' => 'required|min:4'
    ]);

	  $user_data = [
	  'tgi' => $input['tgi'],
	  'password' => $input['password']
	];

//$database = LegonUser::on('mysql2')->select('*')->where($user_data ,'=',         $user_data)->get();
$legonModel = new LegonUser;
$legonDB = \DB::connection('mysql_external');
$logindata = $legonDB->table('emp_username_db')->select('tgi', 'password', 'emp_id')->where(['tgi' => $input['tgi']])->get();

    if ($logindata) {
        print_r($logindata);
        return view('/home');
       }else {
        return "Failed";
        }}

So far I have written query connecting with db2. How shall I write query such that it must login only if the user exists in both databases.

#6

where’s the query to the second database?

$existsBoth ? login() : throw new Exception('user not in both datbases') ;
#7

That’s what I am not getting as I am finding difficulty in writing this query. How to run if condition in the query to check for users in both the databases.

#8

so what does the DB::connection method do? It looks like you can specify a configured connection alias - that way you would just to have to use it twice with different connection aliases.