F
Filament16mo ago
Robin

Fill a selectbox it's option on edit when loaded from relationmanagers

I'm trying to get a relation manager to fill a selectbox that is a couple of relations "away" from the record. This is what I currently have;
Forms\Components\Select::make('product')
->label('Product')
->searchable()
->default(fn(VendingMachineSlot $record) => $record->sellingPointProduct->product->id)
->getSearchResultsUsing(function (RelationManager $livewire, string $search) {
/** @var VendingMachine $ownerRecord */
$ownerRecord = $livewire->ownerRecord;
return $ownerRecord
->sellingPoint
->zone
->zoneProducts()
->join('products', 'product_id', '=', 'products.id')
->where('products.name', 'like', "%$search%")
->select('zones_products.id', 'zones_products.product_id', 'products.name', 'products.id')
->limit(50)
->pluck('product.name', 'product.id');
})
->required(),
Forms\Components\Select::make('product')
->label('Product')
->searchable()
->default(fn(VendingMachineSlot $record) => $record->sellingPointProduct->product->id)
->getSearchResultsUsing(function (RelationManager $livewire, string $search) {
/** @var VendingMachine $ownerRecord */
$ownerRecord = $livewire->ownerRecord;
return $ownerRecord
->sellingPoint
->zone
->zoneProducts()
->join('products', 'product_id', '=', 'products.id')
->where('products.name', 'like', "%$search%")
->select('zones_products.id', 'zones_products.product_id', 'products.name', 'products.id')
->limit(50)
->pluck('product.name', 'product.id');
})
->required(),
Now the error I got is {closure}(): Argument #1 ($record) must be of type App\Models\VendingMachineSlot, null given (default item in the above code) What I need it the selectbox to be filled (and show the item selected) that is found in $record->sellingPointProduct->product->id in where $record should be the "edit" model for the selected relation manager object. Anyone an idea on what and how to do this? Thanks in advance! ❤️
2 Replies
Robin
RobinOP16mo ago
Anyone an idea on how to do this? 😇
Patrick Boivin
Patrick Boivin16mo ago
Can you share the complete table from your relation manager? I think this is missing some context...
Want results from more Discord servers?
Add your server