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

kylemabaso's avatar

Separate views for users based on roles.

Hi Guys. I'm using Spatie for roles and permissions on a Laravel LMS. I want to have an area for teams with a different layout from the main view (separate blade, css and js files). I've read a few posts about using middleware to achieve this (loading separate templates for dashboards), but I'm yet to find anything about a completely different template for the entire app experience. How can I achieve this? I tried using roles like this to no avail:

@hasrole('corpo')
    @extends('theme.corporate')
@else
    @extends('theme.school')
@endhasrole
0 likes
7 replies
jlrdw's avatar

I don't understand. A different dashboard is just a different page. No different when a Doctor's office has a patient portal verses a Doctors portal.

I have one app where the bookkeepers area is different from admin area, just use authentication and authorization.

I don't use middleware for the redirects, just redirect depending on role after logging in. I guess you could do it in middleware, but why.

@hasrole('corpo')
    @extends('theme.corporate')
@else
    @extends('theme.school')
@endhasrole

Why not have their own pages, all the if's / @cans can become a mess, just my opinion.

1 like
kylemabaso's avatar

@jlrdw Yes, a different dashboard is just a different page. What I want to achieve is to change the whole look when you're a patient (navigation, header, footer) and another look when you're a doctor.

jlrdw's avatar

@kylemabaso I still don't understand, then just change the look, via a different layout. You are answering your own question.

1 like
kylemabaso's avatar

@jlrdw I have two layouts, I'm trying to figure out how to use one layout over the other based on your role.

ollie_123's avatar

@kylemabaso as Jlrdw said, you can just use separate layout files and then in your controller/component you can define the layout as follows:-

return view('your-view-name', compact('your_variables'))->layout('layouts.school');
1 like

Please or to participate in this conversation.