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

biha's avatar
Level 1

Different panel for each user with different roles

Hi guys, I want to hear from you what is the best way to create a checking for the user role and redirect to its own panel? For example, I have three roles and I might have more on the future: administrator, costumer, developer. The thing is that I want to avoid breaking the open/closed principle having to edit somewhere everytime I need to add a new panel to an user role. If it where you, what would you do in L5.1?

0 likes
7 replies
biha's avatar
Level 1

I thought in using middlewares, but how I would put there? switches? wouldn't that be weird?

bobbybouwmann's avatar

It's ok to do that, if you want to take it a step further you should be looking at a role system ;)

1 like
TheBlueDragon's avatar

i think in it possible in your controller checking what is the Auth user role and return different view depend on that role

1 like
biha's avatar
Level 1

I will try to implement that, maybe within the role's table I can put the panel path or something and retrieve in the auth controller.

martinbean's avatar

@biha You could add a method to your role model to return the name of the dashboard view to use. You could enforce the presence of this method with an interface, and that way you don’t have to edit middleware classes or whatever each time you add a new role.

class Role extends Model
{
    public function getDashboardView()
    {
        return sprintf('dashboards.%s', $this->slug);
    }
}
class DashboardController extends Controller
{
    public function index()
    {
        return view(Auth::user()->role->getDashboardView());
    }
}
2 likes

Please or to participate in this conversation.