F
Filament17mo ago
toeknee

Passing in parent edit item elements to relationship manager? V2

How can we pass in the parent item into the relationship manager to get some parameters, for example I want to filter by a type of the parent
Solution:
You can use like this in v2. ```php ->options(function (RelationManager $livewire): array { dd($livewire->ownerRecord->id); })...
Jump to solution
2 Replies
Solution
Vp
Vp17mo ago
You can use like this in v2.
->options(function (RelationManager $livewire): array {
dd($livewire->ownerRecord->id);
})
->options(function (RelationManager $livewire): array {
dd($livewire->ownerRecord->id);
})
toeknee
toekneeOP17mo ago
Hero, I was doing it to deep. Resolved with the below
Forms\Components\Select::make('recordId')
->disableLabel()
->label('Select Part to Add')
->preload()
->searchable()
->options(fn(RelationManager $livewire) => \App\Models\Crewing\ContractTemplatesParts::query()
->get()
->mapWithKeys(function($item) use ($livewire) {
$bits = ['title' => $item->title, 'type' => $item->type, 'part' => $item->version, 'ownerRecordId' => $livewire->ownerRecord->id];

return [ $item->id => implode(' - ', $bits)];
})
->toArray()
)
Forms\Components\Select::make('recordId')
->disableLabel()
->label('Select Part to Add')
->preload()
->searchable()
->options(fn(RelationManager $livewire) => \App\Models\Crewing\ContractTemplatesParts::query()
->get()
->mapWithKeys(function($item) use ($livewire) {
$bits = ['title' => $item->title, 'type' => $item->type, 'part' => $item->version, 'ownerRecordId' => $livewire->ownerRecord->id];

return [ $item->id => implode(' - ', $bits)];
})
->toArray()
)

Did you find this page helpful?