Modifying slug in resource class

I have a resource class that's related to a model, and I want to have a url like locations/{location}/vendors/{vendor} to edit the vendors related to the location. However, I don't want to use a RelationManager, I just want to have a separate page where a user can manage the records. I've modified my VendorResource class to attach the slug, and I can link this, but 1, I'm getting a Missing required parameter` error for the location parameter, and 2) how do I ensure that when I load the resource page, it's only pulling the vendors associated with the location.
class VendorResource extends Resource
{
protected static ?string $model = Vendor::class;

protected static bool $shouldRegisterNavigation = false;

protected static ?string $slug = 'locations/{location}/vendors'

...
public static function getPages(): array
{
return [
'index' => Pages\ListVendors::route('/'),
'create' => Pages\CreateVendor::route('/create'),
'edit' => Pages\EditVendor::route('/{record}/edit'),
];
}
}
class VendorResource extends Resource
{
protected static ?string $model = Vendor::class;

protected static bool $shouldRegisterNavigation = false;

protected static ?string $slug = 'locations/{location}/vendors'

...
public static function getPages(): array
{
return [
'index' => Pages\ListVendors::route('/'),
'create' => Pages\CreateVendor::route('/create'),
'edit' => Pages\EditVendor::route('/{record}/edit'),
];
}
}
Here's where I'm linking to the resource class:
$items[] = NavigationItem::make('Vendors')
->icon('heroicon-o-truck')
->group($selectedLocation->name)
->isActiveWhen(fn (): bool => request()->routeIs('filament.app.resources.vendors.*'))
->url(VendorResource::getUrl('index', ['location' => $selectedLocation->id]));
$items[] = NavigationItem::make('Vendors')
->icon('heroicon-o-truck')
->group($selectedLocation->name)
->isActiveWhen(fn (): bool => request()->routeIs('filament.app.resources.vendors.*'))
->url(VendorResource::getUrl('index', ['location' => $selectedLocation->id]));
1 Reply
Jon Mason
Jon Mason9mo ago
Also, not entirely sure when I should reach for a Resource class vs a Page class. 🤷‍♂️