Defining Additional parameters on URL

In my app I have locations, and there's a relationship to month ends. When navigating, I'd like to have my urls be like this as an example: /locations/{location_id}/month-end/202311
The only way that I've seen it work is more like /locations/{location_id}/month-end?yearMonth=202311, which is fine I guess, but I was hoping there is an easy way to not use url parameters if I don't have to. I've tried modifying the $slug property in my resource class, which seems to have some effect, but then I get an error that I'm missing parameters location and yearMonth. If I supply those paremeters it seems to get angry that I haven't supplied the record parameter. I'm a little confused about how the urls are defined as I'm used to just defining them explicitly in the web.php routes file.
class MonthEndTaskResource extends Resource
{
protected static ?string $model = MonthEndTask::class;

protected static ?string $navigationIcon = 'heroicon-o-calendar-days';

protected static bool $shouldRegisterNavigation = false;

// protected static ?string $slug = 'locations/{location}/month-end/{yearMonth}'; <--this causes problems.

...

public static function getPages(): array
{
return [
'index' => Pages\ListMonthEndTasks::route('/'),
'create' => Pages\CreateMonthEndTask::route('/create'),
'edit' => Pages\EditMonthEndTask::route('/{yearMonth}'),
];
}
class MonthEndTaskResource extends Resource
{
protected static ?string $model = MonthEndTask::class;

protected static ?string $navigationIcon = 'heroicon-o-calendar-days';

protected static bool $shouldRegisterNavigation = false;

// protected static ?string $slug = 'locations/{location}/month-end/{yearMonth}'; <--this causes problems.

...

public static function getPages(): array
{
return [
'index' => Pages\ListMonthEndTasks::route('/'),
'create' => Pages\CreateMonthEndTask::route('/create'),
'edit' => Pages\EditMonthEndTask::route('/{yearMonth}'),
];
}
Solution:
e.g.
No description
Jump to solution
4 Replies
Jon Mason
Jon MasonOP15mo ago
After doing some tinkering, I've got a simplified example. I have this slug: protected static ?string $slug = 'locations/{location}/month-ends'; And this in my getPages method:
public static function getPages(): array
{
return [
'index' => Pages\ListMonthEnds::route('/'),
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListMonthEnds::route('/'),
];
}
I'm getting the error:
Missing required parameter for [Route: filament.app.resources.locations.{location}.month-ends.index] [URI: app/{tenant}/locations/{location}/month-ends] [Missing parameter: location].
Missing required parameter for [Route: filament.app.resources.locations.{location}.month-ends.index] [URI: app/{tenant}/locations/{location}/month-ends] [Missing parameter: location].
The location is in the url, so I'm not sure why it's not getting the value. I tried adding a mount method and passing in the location parameter, but that didn't seem to work.
awsqed
awsqed15mo ago
you also need to override the method Resource::getUrl to provide the {location} parameter
Solution
awsqed
awsqed15mo ago
e.g.
No description
Jon Mason
Jon MasonOP15mo ago
ahh ok, that did the trick, thank you!

Did you find this page helpful?