Custom User model
Hi, I need to add some columns to the classic Laravel User model, but it make the filament-user creation fail (because obviously the information for my columns are not asked in the artisan command).
So what can I do in this case ? I see a lot of projects where the User(s) model/table is not really used, and another table for some specific users (app-related) is created. For example a Owner table is created and the Resource for "users" is a OwnerResource. Is it the way to do it ? Only using the classic Laravel User model for the filament-user and having the app users in a more precise user model (Owners, Teachers, ...).
Help would be very appreciated π
8 Replies
User Model just needs more migrations written if you want to add more too it and use it? You can publish it and use that.
If you havce added fields directly to the DB (Which I hope you have not) and they were not originally required, allow them to be nullable
Hi Chriis - you can leave your columns nullable - that should solve the problem?
Yes, so the thing is User model come with "name" but I use "firstname" and "lastname". I still need to have "name" in the model for the filament-user creation but after that I dont use it anymore.
So I can put "name" nullable ?
Yes I have alredy done that
I wouldn't advise it, it's usually advised to duplicate the data
It allows for a specific name seach for example
but when I create a new user, I dont need a name so the form dont have name input
and of course there is a problem, because name cant be null
That's fine, so you ask for first name and last name
but on saving, set name = first_name . ' ' . last_name
well Chriis - you can collect first name / lastname and still manage to club it in the name column
Ah ok, I didn't thought about that π
. I'm going to try
Thanks
Its done with the mutateFormDataBeforeCreate ? Into the CreateUser (of UserResource)