FilamentF
Filament15mo ago
Adysone

Custom resource route with extra parameters

Hello,

I'd like to make this work:

class ContactResource extends Resource
{
    // (...)

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListContacts::route('/{contact_type}/'),
            'create' => Pages\CreateContact::route('/{contact_type}/create'),
            'edit' => Pages\EditContact::route('/{contact_type}/{record}/edit'),
        ];
    }

    // (...)
}


I'd like to preserve the "contact_type" parameter when I edit, create or delete a record in the Contact table.

In the navigation menu, I generate links dynamically according to "Contact types" created by the superadmin, so I came with this in the AdminPanelProvider (with a question in it):

        $thirdPartyContactTypeNavigationItems = ContactType::orderBy('label')
            ->get()
            ->map(function (ContactType $contactType): NavigationItem {
                return NavigationItem::make($contactType->label)
                    ->icon('heroicon-o-users')
                    ->group(__('ThirdParty/main.third_party'))
                    ->isActiveWhen(function () use ($contactType): bool {
                        // How can I get the current value of contact_type?
                    })
                    ->url(fn (): string => ContactResource::getUrl(
                        parameters: ['contact_type' => $contactType->code]
                    ));
            })
            ->all();

        return $panel
            // (...)
            ->navigationItems($thirdPartyContactTypeNavigationItems);


Thanks!
Was this page helpful?