Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shelane's avatar

Routes

I am brand new to Laravel, but I have been doing web development for 20 years. I'm converting an application from an old tech stack that I have and I'm trying to keep URL and parameters as close to the same as possible. I have these URLs that I'm not sure of the right approach to take either with controllers or just using the routes file.

/?events=thisweek (list of events filtered by date range of current week)
/?events=thismonth (list of events filtered by date range of current month)
/?events=current (list of events filtered by today or later)
/?events=current&view=mycal (list of events filtered by today or later and my calendar preferences)
/mycal (calendar selection screen for calendar preferences)
/mysub (calendar selection for subscriptions)
/myreg (list of events I am registered for)
/myevents (list of events I created)
/addevent (create new event)
/event/keyid (a permalink of event by a key field (not database id field))


/admin (list of events I have access to edit)
/admin/admin (list of admin users I can manage)
/admin/calendars/addcalendar (create a new calendar)
/admin/calendars/calendar?series=ABCHAMP (view specific calendar - I'm okay with changing format of URL)
/subscriptions (list of all subscribers by calendar)
0 likes
5 replies
martinbean's avatar

@shelane You might be better off just setting redirects in your .htaccess or nginx config file to be honest.

For example, all of these URIs where you’re using query strings (i.e. /?events=thisweek) will all point to the same route. That means you’re going to have a massive controller with a load of branching logic (if or switch statements) based on query string parameters and their values.

So, I’d just bite the bullet, create an EventController that then uses query string parameters for filtering by date, or for selecting a “view”. You can then set up redirects from the legacy query string-based URIs to your new path-based URIs.

1 like
gych's avatar

For the first 4 URL's you can use a single route and use $request->input('events') and $request->input('view') to access these params in your Controller from the $request.

For the other URL's create separate routes

1 like
amitsolanki24_'s avatar

You can create same route for urls thats has same url but different query string parameters.

martinbean's avatar

@amitsolanki24_ No, you can’t, because query string parameters aren’t used in route URIs. Which is why I said the OP would end up with one route handling many different query strings if they stuck to their current URLs.

Snapey's avatar

/mycal, /mysub, /myreg and /myevents could all be routes to their own controller and then where applicable, create a traits file that applies filters to any model that needs it.

Please or to participate in this conversation.