Crud: [5.0][Refactor] Remove BackpackUser in favour of User

Created on 14 Aug 2019  路  6Comments  路  Source: Laravel-Backpack/CRUD

Upon installing Backpack\Base, Backpack publishes our own model for the admin, BackpackUser. This was done in order to:
1) make the installation as smooth as possible (before this we were asking the developer to add traits to their User model);
2) possibly allow the developer to add methods/attributes only to the admin;

It seems to me like (2) is rarely used, so it doesn't justify the added complexity for everybody.
And (1) can be done in a different way:

  • upon installation, look for App\User.php or App\Models\User.php - if it exists, use that; if not, ask the developer to punch in his custom user model;
  • ask the developer if we can add a few traits to his User model (CrudTrait and a trait that fixes the password reset for admins); if so - add those traits; if not, ask the developer to do it manually;

This breaking change should:

  • make it _a little_ more difficult to install Backpack (reply y/n to prompt in most cases);
  • make it easier to use packages like PermissionManager (see https://github.com/Laravel-Backpack/PermissionManager/issues/183);

Thoughts anyone?

SHOULD

Most helpful comment

Hi there, i think its confussing having two Users models. I agree it would be easier just leaving App/User.php

All 6 comments

Hi there, i think its confussing having two Users models. I agree it would be easier just leaving App/User.php

I agree on the removal, it's tripped me up before forgetting about it, and makes it a bit more complex when thinking about Guards.

Initially I really liked the idea of separating my users from my admins but at the end of the day it just creates unnecessary complexity (particularly when dealing with permissions and guards). I'd be for relying on the User model by default 馃憤

I always use separate model and table for admin user's, I prefer promt with yes/no to add separate model for admins in install process

Originally I dislike it, but now I like having seperate User classes for Admins and normal User

Naming it Staff or Admin may be better

I've just put together a fix for this, in https://github.com/Laravel-Backpack/CRUD/pull/2619. I was able to:

  • remove the need for BackpackUser;
  • (ALSO) remove the need to modify User upon installation;

This way, we have ALL of the benefits of BackpackUser (zero-step installation process, correct notification URLs), with zero added complexity:

Are you doing something to a user? Then it's App/User.

This also fixes A BUNCH of problems with PermissionManager, most notably this one.

I have NOT removed the ability to choose a different User model in config/backpack/base.php. So people like @lotarbo & @ziming are able to easily create a new model (ex: Admin extends User), and use that one in their config. But by default, admins are users. Same db table. Same model.

Let me know what you think in https://github.com/Laravel-Backpack/CRUD/pull/2619 - I'm pretty excited for having this finally solved.

Cheers!

Was this page helpful?
0 / 5 - 0 ratings