thiyagu's avatar

more than one optional parameter in routing url

how to create and work with more than one optional parameter in routing url? Any help?

0 likes
7 replies
danmatthews's avatar

Hey there.

What's the use case? What are you trying to achieve.

You may be able to get away with this using a route slug like:

Route::get('posts/{slug?}/{?edit}', function($slug, $edit) {});

But i'm pretty sure if you omit the first parameter, which i'm assuming you might sometimes do if it's optional, then that would break the URL, and stop it resolving.

Let me know what you're trying to do, and i might be able to help you figure out another way around it!

thiyagu's avatar

HI,

Thank you for your replay.

My use case is /api/v1/products/fashion/key2/watch/key3/style/sortby/byname/page/3/perpage/15

From above url key2, key3, soryby, page, perpage all parameters are optional parameter. How to achieve in lumen routing these all combinations.

Snapey's avatar

you may need to have these as named query string parameters?

/api/v1/products/fashion/key2/watch/key3/style/?sortby=byname&page=3&perpage=15

thiyagu's avatar

Hi snapey,

Thanks for you replay.

In rest api url having query parameter using /?sortby=byname&page=3&perpage=15. It is right way any document?

thiyagu's avatar

Hi snapey,

Thanks for you replay.

Please or to participate in this conversation.