TAGS :Viewed: 7 - Published at: a few seconds ago

[ Redirect user after login based on level in user table - laravel ]

I am using laravel 5

I am using laravel 5.2 In my user table I have added extra column level. I would to redirect users based on the level when they login.

User table

enter image description here

I dont want to use role and permission. Just the user level and redirect.

Answer 1


you have to do this in your login (POST method where user entered credentials are matching)

  if (Auth::attempt(['email' => $email, 'password' => $password])) {

   // Authentication passed... here will be your user lever condition
    if(Auth::user()->level == 'student'){
       return redirect()->route('student-section');
    }

    if(Auth::user()->level == 'teacher'){
       return redirect()->route('teacher-section');
    }

    if(Auth::user()->level == 'admin'){
       return redirect()->route('admin-section');
    }
  }