ManyToMany Relationship Attach Action on Custom Table
public function table(Table $table): Table
{
$merchant = MerchantResolver::resolveMerchant();
return $table
->query($merchant->paymentChannels()->getQuery())
->columns([
TextColumn::make('name'),
TextColumn::make('code'),
])
->actions([
DetachAction::make(),
])
->headerActions([
AttachAction::make(),
]);
}public function table(Table $table): Table
{
$merchant = MerchantResolver::resolveMerchant();
return $table
->query($merchant->paymentChannels()->getQuery())
->columns([
TextColumn::make('name'),
TextColumn::make('code'),
])
->actions([
DetachAction::make(),
])
->headerActions([
AttachAction::make(),
]);
}Is it possible to make AttachAction work? I know I can create my own action button but just wanna know if I can use the default AttachAction to make things cleaner
Solution
Fixed it with this
public function table(Table $table): Table
{
$merchant = MerchantResolver::resolveMerchant();
return $table
->relationship(fn (): BelongsToMany => $merchant->paymentChannels())
->inverseRelationship('merchants')
->columns([
TextColumn::make('name'),
TextColumn::make('code'),
])
->actions([
DetachAction::make(),
])
->headerActions([
AttachAction::make()
->recordTitle(fn (\App\Features\PaymentChannel\Models\PaymentChannel $record): string => $record->name),
]);
}public function table(Table $table): Table
{
$merchant = MerchantResolver::resolveMerchant();
return $table
->relationship(fn (): BelongsToMany => $merchant->paymentChannels())
->inverseRelationship('merchants')
->columns([
TextColumn::make('name'),
TextColumn::make('code'),
])
->actions([
DetachAction::make(),
])
->headerActions([
AttachAction::make()
->recordTitle(fn (\App\Features\PaymentChannel\Models\PaymentChannel $record): string => $record->name),
]);
}