F
Filament16mo ago
Crylar

How to have Resource with custom route parameters?

Lets say I have Menus -> Categories relationship where one Menu has many Categories. I would love to limit a list of Categories to a specific Menu based on the parameter in the URL.
class CategoryResource extends Resource
{
protected static ?string $model = Category::class;

protected static bool $shouldRegisterNavigation = false;

protected static ?string $slug = 'menus/{menu}/categories';
class CategoryResource extends Resource
{
protected static ?string $model = Category::class;

protected static bool $shouldRegisterNavigation = false;

protected static ?string $slug = 'menus/{menu}/categories';
I am getting Missing parameter: menu error when trying to access resource via /admin/menus/1/categories url. I do believe my additional route parameter gets missing from the getUrl generation for all other actions on the table. Please advice.
5 Replies
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Crylar
Crylar16mo ago
Yeh but I am trying to limit my List to a specific Categories related to a defined Menu ID via URL so someone would not need to filter a list to find Categories of a single Menu. So I was wondering if there is a globally acceptable solution to this particular use-case. Usually when building an admin panel it's a pretty common use-case but not sure how to elegantly achieve this in Filament.
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Crylar
Crylar16mo ago
Yeh but I still need to get here. I am getting Missing parameter: menu error when trying to access resource via /admin/menus/1/categories url.
public static function getUrl($name = 'index', $params = [], $isAbsolute = true): string
{
$extraParams = [];

$extraParams['menu'] = Route::current()->parameter('menu');

return parent::getUrl($name, array_merge($extraParams, $params), $isAbsolute);
}
public static function getUrl($name = 'index', $params = [], $isAbsolute = true): string
{
$extraParams = [];

$extraParams['menu'] = Route::current()->parameter('menu');

return parent::getUrl($name, array_merge($extraParams, $params), $isAbsolute);
}
I managed to display a list by overriding getUrl method in the Resource but when I click delete or reorder or filter actions in a List, once again all result into Missing parameter: menu and I got no clue why.
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View