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

xterminator24's avatar

User model best practices

I'm starting a new Laravel 5.8 application and using the built-in Laravel auth.

I know that you can rename the default User model and change the database table name. My question is if that is advisable and if that will make upgrading my Laravel application more difficult as new Laravel versions are released.

For example - If my application has users who are firefighters, it makes more semantic sense in my code to have properties and methods such as firefighter->schedule() or firefighter->name or firefighter->assignedTruck .

Would I be better off just sticking with the default User model, renaming the User model, or creating a "hasOne" eloquent relationship between the User model and a Firefighter model?

0 likes
5 replies
pandell_illmatix's avatar

We use a model like UserRoles as a type of relationship for something like that. This way you can expand on the roles and have multiple roles per user.

jlrdw's avatar

Until you get well acquainted with the authorization I would stick with the way Taylor does it out of the box.

After all the firefighter never sees the word user that's in the code.

After you learn it well then you can start customizing, this is just my opinion.

1 like
tbergman001's avatar

I echo what @jlrdw says, also keep in mind that a lot of the functionality in deeper parts of the auth are not directly relayed to you when creating the authentication scheme for the first time using the make::auth command.

An example of this is customizing the password reset logic and so forth.

Before I would ever start customizing (which I have), run through a hello world app with what you are trying to customize before placing the customization's into a development app.

Also, you can always pull in information from other models and especially with the hasOneThrough() or hasManyThrough().

1 like
Snapey's avatar
Snapey
Best Answer
Level 122

You could perhaps stick with the User model, and use it for authentication, but then create a Firefighter model which extends User.

It does not need to contain any functionality if you don't want, but it could contain relationships etc.

eg;

<?php

namespace App;

use App\User;

class Firefighter extends User
{
    public $table='users';
}

1 like
xterminator24's avatar

Thanks everyone for the responses. I'm going to do a little bit of playing around. I like @snapey 's suggestion because it may make future code upgrades a bit cleaner than shoving a bunch of extra functionality directly on the User model, I can put it in the Firefighter model while still maintaining the default auth behavior.

I really appreciate the feedback!

Please or to participate in this conversation.