1

I'm building an app where I have to show different navigation for users role. However, this is what I've came up with

Navigation example :

<div id="navbar" class="navbar-collapse collapse">
    <ul class="nav navbar-nav navbar-right">
       @if (Auth::check() && Auth::user()->role == 'author')
       <li><a href="{{ url('user/' . Auth::user()->nameslug) }}"><i class="fa fa-user"></i> {{ Auth::user()->name }}</a></li>
       @endif

       @if (Auth::check() && Auth::user()->role == 'admin')
         @if (!empty($page) && $page == 'admin')
           <li class="active"><a href="{{ url('admin') }}"><i class="fa fa-user"></i> Admin</a></li>
         @else
           <li><a href="{{ url('admin') }}"><i class="fa fa-user"></i> Admin</a></li>
         @endif
       @endif

       @if (Auth::check())
       <li><a href="{{ url('logout') }}"><i class="fa fa-sign-out"></i> Logout</a></li>
       @else
          @if (!empty($page) && $page == 'login')
             <li class="active"><a href="{{ url('login') }}"><i class="fa fa-sign-in"></i> Login</a></li>
          @else
             <li><a href="{{ url('login') }}"><i class="fa fa-sign-in"></i> Login</a></li>
          @endif
       @endif
   </ul>   
 </div><!--/.nav-collapse -->

I've tested it and it works just fine, but I'm just wondering if this will affect the app performance, making it slow ? If so is there a better way to do this ? That's all and thanks!

3
  • 1
    As per your requirement, seems okay. Commented Jul 10, 2017 at 7:46
  • 1
    I have used same logic.. Works Perfect..
    – Zedex7
    Commented Jul 10, 2017 at 7:47
  • @SagarGautam even for a high traffic website ? Commented Jul 10, 2017 at 8:03

1 Answer 1

2

This should not impact your application speed. A few if/else blocks won't change much. The roles for this user will be loaded on every page, but this is probably a very light query and Laravel is smart enough to only execute this query once per request.

So conclusion: this looks fine. :)

2
  • 1
    So its fine then, even for a high traffic website ? Commented Jul 10, 2017 at 8:02
  • Yes, this code won't be any problem for a high traffic website.
    – Jerodev
    Commented Jul 10, 2017 at 8:27

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.