Marek
Marek
FFilament
Created by Marek on 4/8/2025 in #❓┊help
Simple question about nested models with Form
Hello, This is my first time using Filament, so please be gentle with me. I've tried to find a solution on-line, including asking AI, but I cannot figure out what I am doing wrong. I got three models: Child, Parent, and Grandparent. Child belongs to Parent, Parent belongs to Grandparent. I would like to display, on the Child view page, values from both Parent and Grandparent. In the form builder I have tried to access their values using dot notation, so it looks like this:
Section::make('Child')
->schema([
TextInput::make('name'),
TextInput::make('parent.name')->label('Parent'),
TextInput::make('parent.grandparent.name')->label('Grandparent'),
])
Section::make('Child')
->schema([
TextInput::make('name'),
TextInput::make('parent.name')->label('Parent'),
TextInput::make('parent.grandparent.name')->label('Grandparent'),
])
Unfortunately, neither parent.name nor parent.grandparent.name values are being populated. I have overloaded ViewRecord::mount() to check if record is populated correctly - it is. I have tried to use ->state(fn (Child $record) => $record->parent->name) to set the value, but this throws an exception about accessing uninitialised $container. Is there a way to build a view page that does not look like a form? I have some resources (or part of resources) I would like to view and never edit. Any help/pointers will be appreciated. Kind regards, Marek
8 replies