F
Filamentβ€’14mo ago
Luukd_2000

Add custom data to the user model after filling in the registration form

Hi, I have two panels. 1 for organisations and 1 for freelancers. When a freelancer creates a new account the account_type column should be set to freelancer. When a organisation creates a new account the account_type column should be set to organisation. Where do I add this?
12 Replies
Luukd_2000
Luukd_2000OPβ€’14mo ago
Thanks but how do I add this to the registration method? I am currenlty using fillaments default registration page
toeknee
toekneeβ€’14mo ago
You have two ways: 1. Add a Laravel model observer 2. Extend the Filament Registration page
Luukd_2000
Luukd_2000OPβ€’14mo ago
Thanks, totally forgot about laravels observers. Thank I will give that a try
Schilly
Schillyβ€’11mo ago
I am trying to do this same thing... But the spatie-role does not want to assign in the observer... Not sure why - its not even throwing an error 😐
toeknee
toekneeβ€’11mo ago
Sounds like the obeserve isn't being triggered.
Schilly
Schillyβ€’11mo ago
That was my first assumption as well...but apparently not? It also randomly started working with no real understanding why lol
toeknee
toekneeβ€’11mo ago
Sounds like caching
Schilly
Schillyβ€’11mo ago
Agreed... I tried clearing said cache on local dev, but it wouldn't work till I uploaded it to prod. Also of note - logging a $user->name worked immediately... Just the the assignRole did not Most strange gremlin situation lol
Anish
Anishβ€’11mo ago
The Observer way seems interesting. In that case there is no need to extend any vendor code. What is the event that the Observer would look for and what data is being passed to the event? Since it is an event in the Vendor (Filament, I assume), one would need to register it manually in the EventServiceProvider, isn't it?
toeknee
toekneeβ€’11mo ago
That would be an event service opposed to an observer. You would want to look at the created and updated methods of the observer
Anish
Anishβ€’11mo ago
Yes, you are right. I got confused between Listeners and Observers. I am sure that Filament must be dispatching an Event when registration happens. It would be ideal to hook into this event. Otherwise it may be difficult to get hold of extra information that may be passed to the registration page. I am at this moment trying to create an application portal for students. The students should register with just the name, email and another field that we plan to put in the registration. This will be used to group the students in different categories. For each category the forms are different. That's why we have thought of capturing it at the time of registration. When the registration happens, we plan to create a corresponding student in the corresponding group . If I just have the Observer on User model on creating, how would I be getting this extra information about the group? Any suggestions
Want results from more Discord servers?
Add your server