How to add relationship form fields on custom pages

I’ve created a custom filament page to display and edit current users details. User model has one to one relationship with UserContact model. In mount method I’ve added $this->form->fill(auth()->user()->load(‘user_contact’)->toArray()); Inside form, I’ve used relationship attribute for user_contact and added user contact fields. I am getting “Call to a member function user_contact() on null” error. My goal is to make a page where current user can edit their details.
No description
1 Reply
IamAStar_1
IamAStar_1OP14mo ago
I’ve figured out the answer. Instead of relationship, I added relationship name example. make(‘user_contact.company’) Inside save method, $data = $this->form->getState(); auth()->user()->update($data); auth()->user()->user_contact->update($userContact); Exception handling and sending success notification is implemented in save()
Want results from more Discord servers?
Add your server