Search code examples
laravellaravel-3

What is the best wat to check if an authenticated user is also an instance of another model?


I am authenticating users with the normal auth eloquent driver.
I want to also check if the User (after logged in) is also an instance of another model.
I found out that he has an array with all of model_2's data but checking if that is empty
sounds like a workaround.
How should I tackle this?

Model 1: Auth::user
Model 2: Teacher

if(Auth::check) {// check for logged in
    if(Auth::user()->is_teacher() ? // -- how can I do this?

Solution

  • Maybe this can work for you:

    $email = Auth::user()->email;
    $match = false;
    
    if (Teacher::where('email','=',$email)->first() != NULL) {
        $match = true;
    }
    
    return $match;