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

UhOh's avatar
Level 7

Route (eg. /home) shared by multiple roles. Your solution?

Route (eg. /home) shared by multiple roles. Your solution?

I simply namespace: /home For the most common user /teachers/home for teacher role

So on. Some people reuse /home but do role checks in the controller which I think is fugly.

So alternatives or solutions you may have?

0 likes
8 replies
UhOh's avatar
Level 7

So you’re pushing the conditional to the view. That’s interesting in general, could be useful in some cases.

But having conditionals in the view rather than controller seems to be just shifting the problem. You still end up with conditionals all over.

I’ve actually been thinking it could be handled via middleware. Wondering if anyone has that approach.

bugsysha's avatar

So you’re pushing the conditional to the view.

That is just a suggestion for you. I do not use that. My code is written in a way that there are no conditionals within controllers or blade files.

UhOh's avatar
Level 7

I avoid conditionals as well. :)

To me namespacing the route is perfectly fine. But some people/projects are OCD about this stuff. So looking for ideas on how else to architect this.

bugsysha's avatar

I encapsulate that logic in an appropriate place/class and use lookup/strategy-pattern. No cleaner/easier way than that.

martinbean's avatar

@uhoh Simple: I don’t have “home” pages for each role and just have a user dashboard. That dashboard then displays whatever content is relevant to that user’s role.

bugsysha's avatar

Give an example from your system what date you have and to what values you want it to correspond.

Please or to participate in this conversation.