Have a method that verifies the logged in users role matches the required Role.
You should really View Jeffries free lessons own Authentication and authorization. They are included in his laravel 7 from scratch series.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I've created a column named as 'role' in Users table there are 3 roles student, teacher, admin I want that when the user enters his credentials he should be redirected to his home page e.g if email = [email protected] password = 1234
then the system should get his role from DB and redirect him to his respected home page (student/home)
Way 1: Go to your Auth/logincontroller and use the method
public function authenticated(Request $request, $user)
{
if($user->role=="student") {
return redirect("/student-home");
}elseif(){
//repeat for rest of the roles
}
}
Way 2: Go to home controller index method and show the blade view based on role.
public function index()
{
if($user->role=="student") {
$data = //collect student related data
return view("student.home",compact("data"));
}elseif(){
//repeat for rest of the roles
}
}
Please or to participate in this conversation.