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:Jump to 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....
12 Replies
Change it in the laravel config. Filament doesn’t care what model the authentication uses.
i want to use 2 different models though for 2 different panels. So I guess that is not possible?
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.
2 models, patients and doctors. Both have different panels
In my mind, that’s still a single user model with different roles.
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?
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.
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.
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.
@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')
@Vp Yes that's what I did, it's a bit of a mess though. But should make things easier.
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.