Relation Manager Resource with pivot - Custom Attach

Hi guys, i create a Relation Manager Resource with pivot. Information: -> Invoice -> it's the Main Resource -> Performance -> it's the Relation Manager Resource -> they have Many to Many relationship. -> it's work, but i need make a change. * I have Product table that has Many Performance, So i need on the popup show a Select for Products, when products Select filter the Performance :
->headerActions([
AttachAction::make()->label('Agregar')
->form(fn (AttachAction $action): array => [
//$action->getRecordSelect(),

Forms\Components\Select::make('product_id')
->relationship('product','external_name')
->afterStateUpdated(fn (callable $set) => $set ('start',null))
->reactive()
->searchable()->required(),
Forms\Components\Select::make('start')
->options(function (callable $get){

$product = Product::find($get('product_id'));
if (!$product)
{
return [];
}
return $product->performances()->pluck('start','id');
})->required()

]),
])
->headerActions([
AttachAction::make()->label('Agregar')
->form(fn (AttachAction $action): array => [
//$action->getRecordSelect(),

Forms\Components\Select::make('product_id')
->relationship('product','external_name')
->afterStateUpdated(fn (callable $set) => $set ('start',null))
->reactive()
->searchable()->required(),
Forms\Components\Select::make('start')
->options(function (callable $get){

$product = Product::find($get('product_id'));
if (!$product)
{
return [];
}
return $product->performances()->pluck('start','id');
})->required()

]),
])
The form works but when a click on Attach i got an error:
Undefined array key "recordId"
Undefined array key "recordId"
I imagine that to solve this I should use:
Relation Manager Resource with pivot - Custome Attach
Relation Manager Resource with pivot - Custome Attach
But I do not know how to do it
4 Replies
Dennis Koch
Dennis Koch2y ago
Why did you comment out //$action->getRecordSelect(), ? I guess that's your issue
marianov24
marianov24OP2y ago
I commented it because it adds another field for me. This field works to attach but I need to previously filter by products
Dan Harrin
Dan Harrin2y ago
product_id should be recordId then you cant go renaming fields without consequences like that... i would even advise using $action->getRecordSelect() as a base for your select and chaining customization methods onto that
marianov24
marianov24OP2y ago
omg I love filament and this wonderful community more and more Working:
->headerActions([
AttachAction::make()->label('Agregar')
->form(fn (): array => [
Forms\Components\Select::make('product_id')
->relationship('product','external_name')
->afterStateUpdated(fn (callable $set) => $set ('start',null))
->reactive()
->searchable()->required(),
Forms\Components\Select::make('recordId')
->options(function (callable $get){

$product = Product::find($get('product_id'));
if (!$product)
{
return [];
}
return $product->performances()->pluck('start','id');
})->required()

]),
])
->headerActions([
AttachAction::make()->label('Agregar')
->form(fn (): array => [
Forms\Components\Select::make('product_id')
->relationship('product','external_name')
->afterStateUpdated(fn (callable $set) => $set ('start',null))
->reactive()
->searchable()->required(),
Forms\Components\Select::make('recordId')
->options(function (callable $get){

$product = Product::find($get('product_id'));
if (!$product)
{
return [];
}
return $product->performances()->pluck('start','id');
})->required()

]),
])
Want results from more Discord servers?
Add your server