Multi-db support
This commit is contained in:
parent
97c2a35868
commit
2e0cd34bf8
2 changed files with 12 additions and 6 deletions
|
|
@ -142,7 +142,7 @@ class AuthController extends Controller
|
|||
*/
|
||||
public function postLoginWrapper(Request $request)
|
||||
{
|
||||
LookupUser::loadEmail($request->input('email'));
|
||||
LookupUser::setServerByEmail($request->input('email'));
|
||||
|
||||
$userId = Auth::check() ? Auth::user()->id : null;
|
||||
$user = User::where('email', '=', $request->input('email'))->first();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Models;
|
||||
|
||||
use Eloquent;
|
||||
use App\Models\User;
|
||||
|
||||
/**
|
||||
* Class ExpenseCategory.
|
||||
|
|
@ -18,7 +19,7 @@ class LookupUser extends LookupModel
|
|||
'user_id',
|
||||
];
|
||||
|
||||
public static function loadEmail($email)
|
||||
public static function setServerByEmail($email)
|
||||
{
|
||||
if (! env('MULTI_DB_ENABLED')) {
|
||||
return;
|
||||
|
|
@ -28,10 +29,15 @@ class LookupUser extends LookupModel
|
|||
config(['database.default' => DB_NINJA_LOOKUP]);
|
||||
|
||||
if ($lookupUser = static::whereEmail($email)->first()) {
|
||||
session(['SESSION_DB_SERVER' => $lookupUser->getDbServer()]);
|
||||
$server = $lookupUser->getDbServer();
|
||||
session(['SESSION_DB_SERVER' => $server]);
|
||||
config(['database.default' => $server]);
|
||||
|
||||
if (! User::whereEmail($email)->first()) {
|
||||
abort('Lookedup user not found: ' . $email);
|
||||
}
|
||||
} else {
|
||||
config(['database.default' => $current]);
|
||||
}
|
||||
|
||||
config(['database.default' => $current]);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue