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:
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,
Marek6 Replies
Have you defined the relations in the Model correctly?
Yes...infolist.
Yes, relationships in model are set correctly, I can render data without issues using the
Placeholder
.Have you tried this method? https://filamentphp.com/docs/3.x/forms/fields/select#creating-a-new-option-in-a-modal
you have to define the field as a relationship if I'm not mistaken
I have not tried this, but I have found
Placeholder
that works better for me.