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:
The only way that I've seen it work is more like
/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.
4 Replies
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:
I'm getting the error:
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.you also need to override the method
Resource::getUrl
to provide the {location} parameterSolution
e.g.
ahh ok, that did the trick, thank you!