Reputation: 165
I'm trying to achieve the following routing in Laravel
/stats/{id}
/stats/{id}/limit/{limit}
/stats/{id}/limit/{limit}/order/{order}
/stats/{id}/order/{order}
/stats/{id}/order/{order}/limit/{limit}
As you can see, only {id} is required, /limit/ and /order/ may or may not appear and their order shouldn't matter.
Thank you!
Upvotes: 1
Views: 168
Reputation: 99
I'm not sure what you're trying to achieve but I think that the best approach to this is to send limit
and order
as query params instead of creating route options for them. Like:
/stats/{id}?order={order}&limit={limit}
This way you can add as many optional params as you want.
Upvotes: 2
Reputation: 2416
Use ?
a question mark after parameter. Like:
/stats/{id}/order/{order?}/limit/{limit?}
Source: Laravel Route Optional Parameters
Upvotes: 0