Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Laravel 5.0 handling multiple layouts - Select layout as per the user role

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 523
    Comment on it

    Hi Readers

    Recently when I was working in Laravel, I came across an issue. It was regarding the selection of a particular layout as per the logged-in user. I have to show a particular layout according to the role of the user logged-in. When I used extends($layout) in if condition some how all the layout got included and hence I came out with an alternative solution.


    To overcome the above stated problem follow the following procedure.


    Syntax :-

    <?php $layout = 'layouts.master'; ?>
    @if(Auth::check())
        @if(Auth::user()->role == 'ngo')
            <?php $layout = 'layouts.ngo_master'; ?>
        @elseif(Auth::user()->role == 'company')
            <?php $layout = 'layouts.admin_master'; ?>
        @endif
    @endif
    @extends($layout)
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: