Hey. I have an application to which I sell access to a group of customers - paid subscription. Each buyer receives his subdomain and database with many tables. Each buyer provides the key to his subdomain to his employees so that they can register and log in.
Each such subdomain is now a separate Laravel instance. Due to the fact that I have more and more clients, maintaining coherence between instances becomes difficult. In addition, I want to extend the application with a mobile application that needs a good api.
I am creating an API that should be able to handle multiple databases simultaneously. Each base is constructed the same way. So I would like one model or controller to be able to handle data from different databases.
The API requires authorization and this is where my problem comes from. Because I have users in different databases, I don't know how to check if the given email and password are correct.
When logging in, the application on the user's side sends an email, password and unit, which means which database to use. But how can I tell the Auth class which database to use?
My current LoginController@login looks like this:
function login() {
// In request()->input('unit') i have database name
// Before Auth::attempt i want to say laravel to use specific db.. how to tell it him ?
if( Auth::attempt(['email' => request()->input('email'), 'password' => request()->input('password')]) ) {
$user = Auth::user();
$user->generateToken();
return response()->json(
$user->api_token
, 200);
}
return response()->json([
"error" => "Unauthenticated."
], 401);
}
PS. I don't use Passport or JWT - only my code
PS2. Of course all databases are included in config/database.php