В режиме hyn / multi-tenancy после переопределения метода входа в LoginController и в рамках этого метода подключите базу данных клиентов. Он успешно регистрируется, если я печатаю результаты входа, но когда я перенаправляю его на homeController, он снова перенаправляет на страницу входа, а не go на домашнюю страницу. Я использую https://github.com/peartreedigital/boilerplate пример изменения только в loginController, который
class LoginController extends Controller
{
use AuthenticatesUsers;
public function username()
{
$login = request()->input('identity');
$field = filter_var($login, FILTER_VALIDATE_EMAIL) ? 'email' : 'username';
request()->merge([$field => $login]);
return $field;
}
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function validateLogin(Request $request)
{
$messages = [
'identity.required' => 'Email or username cannot be empty',
'email.exists' => 'Email or username already registered',
'username.exists' => 'Username is already registered',
'password.required' => 'Password cannot be empty',
];
$request->validate([
'identity' => 'required|string',
'password' => 'required|string',
'email' => 'string|exists:users',
'username' => 'string|exists:users',
], $messages);
$domain_name = $request->get('domain_name');
$usernameatacc = $request->get('identity');
$password = $request->get('password');
$hostname = DB::table('hostnames')->select('*')->where('fqdn', $domain_name)->first();
$dbname = DB::table('websites')->select('uuid')->where('id', $hostname->website_id)->first();
Config::set("database.connections.tenant", [
"driver" => 'mysql',
"host" => '127.0.0.1',
"database" => $dbname->uuid,
"username" => 'root',
"password" => ''
]);
Config::set('database.default', 'tenant');
DB::purge('tenant');
DB::reconnect('tenant');
}
public function login(Request $request)
{
$this->validateLogin($request);
$user_data = User::where('email', $request->get('identity'))
->first();
$matchPwd = Hash::check($request->get('password'), $user_data->password);
if ($matchPwd == '1') {
// print_r($user_data);
// Here What can I do????? Please help
}else {
return redirect()->back()->withErrors($user_data);
}
}
protected function guard()
{
return Auth::guard();
}
}
Моя форма входа в login.blade. php is
<form method="POST" action="{{ route('login') }}">
@csrf
<div class="form-group row">
<label for="domain_name" class="col-sm-4 col-form-label text-md-right">{{ __('Domain Name') }}</label>
<div class="col-md-6">
<input id="domain_name" type="domain_name" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="domain_name" value="{{ old('domain_name') }}" required autofocus>
@if ($errors->has('domain_name'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('domain_name') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="email" class="col-sm-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="identity" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
@if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="form-check">
<input class="form-check-input" type="checkbox" name="remember" id="remember" {{ old('remember') ? 'checked' : '' }}>
<label class="form-check-label" for="remember">
{{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
</div>
</div>
</form>