© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•6mo ago•
3 replies
Merdin

How to call parent record in a nested form?

What I am trying to do:
I have a
AssignmentResource
AssignmentResource
that is a nested resource of the
ProjectResource
ProjectResource
. In my form I want to get the contacts of the project.

What I did:
Look at the code

My issue/the error:
I found a way to do it, but it gives me errors with PHPStan so I was wondering if there is a better / alternative way to do it.

Code:
final class AssignmentForm
{
    public static function configure(Schema $schema): Schema
    {
        // @phpstan-ignore-next-line
        $project = $schema->getLivewire()?->parentRecord;

        return $schema
            ->components([
                Select::make('contact_id')
                    ->label(__('Contact'))
                    ->relationship('project.relation.contacts', 'name',
                        modifyQueryUsing: function ($query) use ($project) {
                          if (empty($project)) {
                              $query->whereRaw('1 = 0'); // No project available, return empty result set
                              return;
                          }

                          $query->where('relation_id', $project->relation_id);
                    }),

                // ...
            ]);
    }
}
final class AssignmentForm
{
    public static function configure(Schema $schema): Schema
    {
        // @phpstan-ignore-next-line
        $project = $schema->getLivewire()?->parentRecord;

        return $schema
            ->components([
                Select::make('contact_id')
                    ->label(__('Contact'))
                    ->relationship('project.relation.contacts', 'name',
                        modifyQueryUsing: function ($query) use ($project) {
                          if (empty($project)) {
                              $query->whereRaw('1 = 0'); // No project available, return empty result set
                              return;
                          }

                          $query->where('relation_id', $project->relation_id);
                    }),

                // ...
            ]);
    }
}
Solution
PHPStan will give errors in Laravel natively, ensure you are using Laravels IDE Helper too.

But the parentRecord is the recommended approach.
Jump to solution
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

Nested Actions, Parent Form validation
FilamentFFilament / ❓┊help
10mo ago
How to call a function in another service on saving a form record?
FilamentFFilament / ❓┊help
3y ago
Access Parent Record In forms or anywhere of nested resources
FilamentFFilament / ❓┊help
4mo ago
Access parent record in RepeatableEntry
FilamentFFilament / ❓┊help
3y ago