relationManger nested

I'm building admin and user panel with filament. in admin panel i have a usersResource and relationManger that is name is "CampaignsRelationManager". in user panel i have a campaigns resource and relationManger that is name is "CampCouponRelationManager". i want to add CampCouponRelationManager to CampaignsRelationManager under the admin panel. Basically, it means to create a relationManger inside a relationManger
Solution:
Yeah sure, it is just a custom action on the table: Inside your relationmanager in the actions array you can do something like this: ```php ->actions([...
Jump to solution
7 Replies
Blackpig
Blackpig4mo ago
Take a look at guava-nested-resource plugin - it's still in alpha but handles simple nesting (I use it in a project that required 4 level deep RM nesting) https://discord.com/channels/883083792112300104/1167940700130791574 I believe native filament support for nested resources is on the v4 roadmap
ramclospapp
ramclospapp4mo ago
I will check it. Thank you!
gladjanus43
gladjanus434mo ago
I had a similar requirement but didnt like all the relation manager under eachother. I made a slide over with a repeater in it. I think this is better UX if there are not a lot of records in the "relation of the relation" I can share the code if you want!
ramclospapp
ramclospapp4mo ago
Thanks! It will also work well if the coupons appear as a resource in the user's panel? I'm pretty new to filament..
Solution
gladjanus43
gladjanus434mo ago
Yeah sure, it is just a custom action on the table: Inside your relationmanager in the actions array you can do something like this:
->actions([
Action::make('attachments')
->label(fn($record) => 'Attachments (' . $record->attachments->count() . ')')
->icon('heroicon-o-paper-clip')
->fillForm(fn(Product $record): array => [
'attachments' => $record->attachments
])
->modalHeading('Product Attachments toevoegen')
->modalDescription('Attachments zijn toevoegingen aan je product. Denk hierbij aan sloten, bekleden met stof of ander materiaal/opties die je aan de kist zou kunnen toevoegen. Heb je vragen over attachments? Bel ons dan op.')
->modalIcon('heroicon-o-link')
->modalSubmitActionLabel('Toevoegen')
->form(
AttachmentRelationResources::getAttachmentRepeaterForm()
)
->hidden(fn($livewire) => in_array($livewire->ownerRecord->status->name, ['ACCEPTED', 'PRODUCTION', 'TO_INVOICE', 'INVOICED', 'CANCELLED']))
->slideOver()
])
->actions([
Action::make('attachments')
->label(fn($record) => 'Attachments (' . $record->attachments->count() . ')')
->icon('heroicon-o-paper-clip')
->fillForm(fn(Product $record): array => [
'attachments' => $record->attachments
])
->modalHeading('Product Attachments toevoegen')
->modalDescription('Attachments zijn toevoegingen aan je product. Denk hierbij aan sloten, bekleden met stof of ander materiaal/opties die je aan de kist zou kunnen toevoegen. Heb je vragen over attachments? Bel ons dan op.')
->modalIcon('heroicon-o-link')
->modalSubmitActionLabel('Toevoegen')
->form(
AttachmentRelationResources::getAttachmentRepeaterForm()
)
->hidden(fn($livewire) => in_array($livewire->ownerRecord->status->name, ['ACCEPTED', 'PRODUCTION', 'TO_INVOICE', 'INVOICED', 'CANCELLED']))
->slideOver()
])
gladjanus43
gladjanus434mo ago
And AttachmentRelationResources::getAttachmentRepeaterForm() is where I retrieve the form In my case it is
public static function getAttachmentRepeaterForm(): array
{
return [
Repeater::make('Attachments')
->relationship('attachments')
->columns(2)
->hiddenLabel()
->deleteAction(
function ($action) {
$action->requiresConfirmation();
$action->before(function (array $arguments, Repeater $component) {
$itemData = $component->getItemState($arguments['item']);
AttachmentService::deleteAttachment(Attachment::find($itemData['id']));
});
}
)
->schema([...])
]}
public static function getAttachmentRepeaterForm(): array
{
return [
Repeater::make('Attachments')
->relationship('attachments')
->columns(2)
->hiddenLabel()
->deleteAction(
function ($action) {
$action->requiresConfirmation();
$action->before(function (array $arguments, Repeater $component) {
$itemData = $component->getItemState($arguments['item']);
AttachmentService::deleteAttachment(Attachment::find($itemData['id']));
});
}
)
->schema([...])
]}
ramclospapp
ramclospapp4mo ago
Thank you so much!
Want results from more Discord servers?
Add your server
More Posts