F
Filamentβ€’15mo ago
Chriis

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
toeknee
toekneeβ€’15mo ago
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
blakdronzer
blakdronzerβ€’15mo ago
Hi Chriis - you can leave your columns nullable - that should solve the problem?
Chriis
ChriisOPβ€’15mo ago
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
toeknee
toekneeβ€’15mo ago
I wouldn't advise it, it's usually advised to duplicate the data It allows for a specific name seach for example
Chriis
ChriisOPβ€’15mo ago
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
toeknee
toekneeβ€’15mo ago
That's fine, so you ask for first name and last name but on saving, set name = first_name . ' ' . last_name
blakdronzer
blakdronzerβ€’15mo ago
well Chriis - you can collect first name / lastname and still manage to club it in the name column
Chriis
ChriisOPβ€’15mo ago
Ah ok, I didn't thought about that πŸ˜…. I'm going to try Thanks Its done with the mutateFormDataBeforeCreate ? Into the CreateUser (of UserResource)
Want results from more Discord servers?
Add your server