F
Filament15mo ago
Chriis

How to work with a 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.
3 Replies
DrByte
DrByte15mo ago
A few things you could consider: You could extend the command and add your additional fields to it. Or you could make the fields nullable in the db so that it doesn't fail when they're not provided. And then maybe you could get the user to update them by making them required whenever they edit their profile. Or you could listen to the model's creating event and fill in the value with a default if the application is running from console.
Chriis
ChriisOP15mo ago
Hi, my bad. I found a solution in another discussion and didn't close this one. However, I'm interested in your first suggestion. I was initially thinking about that, but I have no idea how or where I can extend the command.
DrByte
DrByte15mo ago
Extending a command is just like extending any other class, and then overriding whatever properties/methods you wish to customize. You could make a new command with artisan and then manually change it from extending Command to extending Filament\Commands\MakeUserCommand ... and then override the $description and $signature properties (maybe the docblock on $options too) and the getUserData() method. See the original Command code in the repo: https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Commands/MakeUserCommand.php#L18-L56
GitHub
filament/packages/panels/src/Commands/MakeUserCommand.php at 3.x · ...
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Want results from more Discord servers?
Add your server