F
Filament6mo ago
MZX

How do I use a different model for the auth?

I have a Patient model which I would like to use as the default user model, how would I change that?
Solution:
If anyone comes across this, you have to create the guard in config/auth.php And then you have to make sure the model you're trying to use for auth has the same properties as that of user. Make sure the password is using bcrypt, and its a protected cast....
Jump to solution
12 Replies
awcodes
awcodes6mo ago
Change it in the laravel config. Filament doesn’t care what model the authentication uses.
MZX
MZXOP6mo ago
i want to use 2 different models though for 2 different panels. So I guess that is not possible?
awcodes
awcodes6mo ago
Maybe dig more into the use case with laravel. I’m not totally understanding the use case where there’s 2 different user models. A user is a user, what they have access to in the system is defined by their roles and permissions.
MZX
MZXOP6mo ago
2 models, patients and doctors. Both have different panels
awcodes
awcodes6mo ago
In my mind, that’s still a single user model with different roles.
MZX
MZXOP6mo ago
True they can have different roles, but those models have different attributes. I can't put them into a single model Is there anything you'd like to suggest?
awcodes
awcodes6mo ago
A single user model can still have different attributes though a relationship to the role or some something like “profiles” that can be a relationship in and of itself. Keep in mind the authentication and authorization are two different concepts.
MZX
MZXOP6mo ago
That's true. I am not sure about your approach, I believe it would be difficult to implement compared to just having 2 different models.
awcodes
awcodes6mo ago
It will be easier to a roles for all users. A user can either have a role of doctor or patient. Then you’d use those roles to guard against what they are authorized to do in the app. It will be a lot simpler with laravel conventions than two different models. I promise. If 2 different models was easier you probably wouldn’t be in this situation right now. I could be wrong, though. Just my experience.
Vp
Vp6mo ago
@MZX if you configure everything correctly in laravel (creating different guard etc) then you can put this in panelProvider to make it able to login for different guard ->authGuard('guard_name')
MZX
MZXOP6mo ago
@Vp Yes that's what I did, it's a bit of a mess though. But should make things easier.
Solution
MZX
MZX6mo ago
If anyone comes across this, you have to create the guard in config/auth.php And then you have to make sure the model you're trying to use for auth has the same properties as that of user. Make sure the password is using bcrypt, and its a protected cast.
Want results from more Discord servers?
Add your server