Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thebigk's avatar
Level 13

Using 'Auth' for multiple models

Typically a Laravel app has a User model and Laravel provides Auth system for it. I can use the Auth facade to achieve quick login.

However, my application has two different types of models; say Teacher and Student. These models refer to different tables internally.

I'm wondering how could I use Auth for these two different models in my application?

Would really appreciate your support.

0 likes
6 replies
thebigk's avatar
Level 13

Hello @corvs - is there any specific reason? I'm developing a mult-tenant application and after much consideration, I've concluded that it's better to have two different models.

For example, the Teacher model will have all the column supported by Laravel Cashier; while students model will have different set of columns.

Also, I'll need multiple unique columns on student and teacher model. That's the reason I was thinking of using two different models.

CorvS's avatar

@thebigk Two different models for teachers and students are completely fine, but use the User model for authentication and a user can be a teacher or student then (or both).

Snapey's avatar

What if a student needs to be a teacher, or vice versa. Doing this is not a good idea as it makes life a lot more complex.

thebigk's avatar
Level 13

@snapey - that will never be the case. I just stumbled upon the following block in config/auth.php -

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],

Though I'm thinking of switching to just User model; I'm curious to know if the above block actually does what I'm trying to do.

mabdullahsari's avatar

You're reaching for the wrong tool here, tbh. What you need is Multi-Table Inheritance. You can read the README of this repo and if you have more questions, feel free to ask.

Please or to participate in this conversation.