I've been planning to make one login page for different types of users and it will be able to direct them to their intended dashboards/homepages. These are my two users:
- Traveler
- Agent
The traveler can successfully login and will be directed to the intended homepage BUT the Agent wont be directed to its intended homepage instead it will be directed back to the login page.
This is my code of the Login Controller
<?php
namespace App\Http\Controllers\Auth;
use Auth;
use App\Travelers;
use App\Agents;
use App\Users;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function login(Request $request){
if(Auth::attempt([
'email' => $request->email,
'password' => $request->password
])){
$user = Users::where('email', $request->email)->first();
switch ($user->userType){
case 'traveler':
return redirect()->route('Traveler/HomePage');
break;
case 'travel agent':
return redirect()->route('Agent/HomePage');
break;
}
}
else{
return redirect()->route('login');
}
}
}