Access Parent Record In forms or anywhere of nested resources
I want to access parent resource in form class of a nested resource:
TextInput::make('order')
->label('Display Order')
->numeric()
->minValue(1)
->default(fn ($livewire) => $livewire->getOwnerRecord()->categories()->max('order') + 1 ?? 1)
->helperText('Order in which this category appears in scoring forms (1 = first)')
->disabled(fn (?string $operation) => $operation !== Operation::Create->value),
TernaryFilter::make('has_completed_scoring')
->label('Completed Scoring')
->queries(
true: fn (Builder $query, Page $livewire) => self::filterCompletedScoring($query, $livewire->getParentRecord(), true),
false: fn (Builder $query, Page $livewire) => self::filterCompletedScoring($query, $livewire->getParentRecord(), false),
),
Now how to access it and which livewire should I import?
And how to do it for Actions? Filters?2 Replies
you are doing it above already? getOwnerRecord? But you can also pass in $record to the function, which will pass in the parent record if it's not a relationship. But you need to be more specific and explanatory where you are not able to access it.
I'm inside a Table class for a nested resource and I need to get the parent record or inside a Form class of a nested resource.
Will Page be resolved anywhere?