Come ottenere il modello dell'utente attualmente connesso?

Aug 18 2020

Come posso ottenere il modello dell'utente attualmente connesso? Ad esempio, se ci sono due tipi di utenti in staff di sistema e admin? come faccio a sapere da quale modello appartiene l'utente?

Auth::user()->?

Risposte

3 ajthinking Aug 18 2020 at 13:56

Puoi usare il get_classmetodo integrato ?

get_class(Auth::user())
3 Egretos Aug 18 2020 at 14:00

Prova a usare instanceof.

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

if (Auth::user() instanceof Staff) {
// DO another
}