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

NoobDev0410's avatar

Making Routes Based on User roles

Hello

i am making an app for practice with multiple roles admin supervisor, employer.

I am Struggling to decide weather to include the user role in the URL of each user's dashboard or render the view based on the role of the user while not including it in the URL. Is there A good recommended approach to solve this. All of my dashboards have the same layout which only different in the amount of options in the sidebar per role.

case-1: 'admin/employeer/1/edit'

case-2 : 'employer/employeer/1/edit'

what will be good?

1 like
6 replies
jlrdw's avatar
jlrdw
Best Answer
Level 75

Suggest you use authentication for login and use authorization to determine who can do what with their role.

Many good past discussions on this setup.

You do not need it in the url, I wouldn't.

1 like
NoobDev0410's avatar

@jlrdw Thanks sir. Is there any specific reason for not needing it in the URL. I cant think of any. thanks for answering my question.

Snapey's avatar

create one dashboard and hide the things the user cannot access

use the built in authorization functions and @can to reveal sidebar buttons etc only available to that role. Then, where the button leads to a restricted function, use middleware to block access to the urls (dont just rely on the role not seeing the button)

1 like
NoobDev0410's avatar

@Snapey thanks sir. i am using the admin lte package there fore i can use gates in the admin lte config file. I also had made common dashboard blade and different role folders in the views that extends to from it. and using the gates to authorize the role in the controllers. if different roles needs to access a index method of controller i decided to return the views based on the role of the user in that.

Is this approach okay sir. thanks

Please or to participate in this conversation.