© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
4 replies
Jon Mason

odd form behavior on relationship

From reading through topics and the docs, I've gathered that in order to use a relationship on a form field, I need to use a form layout component and set the relationship.

I have a form in a page component that I'm not populating until the user clicks a button. I'm able to populate the form with what I've got right now, but when it comes time to save,
$this->form->getState()
$this->form->getState()
returns one field but not the one with the relationship.

mount method:

$this->form->fill([
            'accountNote' => ['notes' => ''],
            'preparer_comments' => ''
        ]);
$this->form->fill([
            'accountNote' => ['notes' => ''],
            'preparer_comments' => ''
        ]);


method to populate form:

public function showEditModal($id)
    {

        // Fetch the row data based on ID
        $this->editItem = BalanceSheet::find($id);
        // dd($this->editItem);
        $this->form->fill([
            'preparer_comments' => $this->editItem->preparer_comments,
            'accountNote' => $this->editItem->accountNote //can't seem to set just the field on this, have to set the entire relationship.
        ]);

        $this->dispatch('open-modal', id: 'editRowModal');
    }
public function showEditModal($id)
    {

        // Fetch the row data based on ID
        $this->editItem = BalanceSheet::find($id);
        // dd($this->editItem);
        $this->form->fill([
            'preparer_comments' => $this->editItem->preparer_comments,
            'accountNote' => $this->editItem->accountNote //can't seem to set just the field on this, have to set the entire relationship.
        ]);

        $this->dispatch('open-modal', id: 'editRowModal');
    }


the form:

public function form(Form $form): Form
    {
        return $form->schema([
            Grid::make()
                ->columns(1)
                ->relationship('accountNote')
                ->schema([
                    Textarea::make('notes')
                        ->label('Account Notes')
                        ->rows(6),
                ]),
            Textarea::make('preparer_comments')
                ->label('Preparer Comments')
                ->rows(6),

        ])->statePath('data')
            ->model(BalanceSheet::class);
    }
public function form(Form $form): Form
    {
        return $form->schema([
            Grid::make()
                ->columns(1)
                ->relationship('accountNote')
                ->schema([
                    Textarea::make('notes')
                        ->label('Account Notes')
                        ->rows(6),
                ]),
            Textarea::make('preparer_comments')
                ->label('Preparer Comments')
                ->rows(6),

        ])->statePath('data')
            ->model(BalanceSheet::class);
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

weird select option behavior on relationship
FilamentFFilament / ❓┊help
2y ago
->relationship() on form field directly?
FilamentFFilament / ❓┊help
4mo ago
Form Toggle relationship
FilamentFFilament / ❓┊help
3y ago