I am creating a Laravel based web page. I am using Laravel Framework 5.8.11 I am trying to make one login form, that will use users from two sql tables. The tables are "persons" and "companies". They both need to sign in on one login modal that i am using. So, one login (email and password), and after login they need to get a view based on what table do they belong, persons or companies.
I don't know what am i doing wrong? I have to have just one login, not two seperate.
I tried making new guards.
I added protected $guard = 'company'; and one for persons to models.
After that i added guards and providers to config/auth.php
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
'person' => [
'driver' => 'session',
'provider' => 'persons',
],
'company' => [
'driver' => 'session',
'provider' => 'companies',
],
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'person' => [
'driver' => 'eloquent',
'model' => App\Model\Person::class,
],
'company' => [
'driver' => 'eloquent',
'model' => App\Model\Company::class,
],
],
After that i edited Http/Controllers/Auth/LoginController.php
...
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('guest:person')->except('logout');
$this->middleware('guest:company')->except('logout');
}
...
public function frontendLogin(Request $request) {
if(request()->isMethod('post')){
//form validation
request()->validate([
'email' => 'required|string|email',
'password' => 'required'
]);
if (Auth::guard('person')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {
return redirect()->intended(route('contact'));
}
if (Auth::guard('company')->attempt([
'email' => request('email'),
'password' => request('password'),
'active' => 1,
'deleted' => 0,
])){
return redirect()->intended(route('homepage') );
}
}
return view('homepage');
The routes i placed for after login are just for test. They are defined. After creating a login view and trying to login i get a 404 for route /home. That route is not defined, and i don't know why is it redirecting me there