-1

How i can get model of current logged in user? For example if there are two types of users in system staff and admin? how would i know from which model user belongs?

Auth::user()->?
  • https://stackoverflow.com/questions/30411585/different-user-types-laravel – hatsagorts Aug 18 '20 at 06:58
  • maybe something like : if (Auth::user()->is_admin==true) – OMR Aug 18 '20 at 06:58
  • The solution is not straightforward. But there is a nice example here: https://stackoverflow.com/questions/34614753/can-anyone-explain-laravel-5-2-multi-auth-with-example – Dan Aug 18 '20 at 07:00
  • You should create a flag for this in user table.or use guard. auth()->guard('web')->user() – hammad khan Aug 18 '20 at 07:02

2 Answers2

3

Try to use instanceof.

if (Auth::user() instanceof Admin) {
// DO something
}

if (Auth::user() instanceof Staff) {
// DO another
}
Egretos
  • 1,155
  • 7
  • 23
2

You can use the built in get_class method?

get_class(Auth::user())
ajthinking
  • 3,386
  • 8
  • 45
  • 75