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
Thanks but how do I add this to the registration method? I am currenlty using fillaments default registration page
You have two ways:
1. Add a Laravel model observer
2. Extend the Filament Registration page
Thanks, totally forgot about laravels observers. Thank I will give that a try
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 π
Sounds like the obeserve isn't being triggered.
That was my first assumption as well...but apparently not? It also randomly started working with no real understanding why lol
Sounds like caching
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
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?
That would be an event service opposed to an observer. You would want to look at the created and updated methods of the observer
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