title: How can I use Middleware to define a section of a blade template?
body: <p>I have navigation bar that I'd like to show a link to the Admin Dashboard if the user logged in is an admin. If not, it should display nothing. I have something similar set up with guests e.g.</p>
  
  <pre><code>@if (Auth::guest())
          &lt;li&gt;&lt;a href="{{ url('/auth/login') }}"&gt;Login&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="{{ url('/auth/register') }}"&gt;Register&lt;/a&gt;&lt;/li&gt;
      @else
          &lt;li class="dropdown"&gt;
              &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"&gt;{{ Auth::user()-&gt;name }} &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
              &lt;ul class="dropdown-menu" role="menu"&gt;
                  &lt;li&gt;&lt;a href="{{ url('/profile') }}"&gt;Profile&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="{{ url('/auth/logout') }}"&gt;Logout&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/li&gt;
  @endif
  </code></pre>
  
  <p>But how can I do this for a logged in user and an admin? I currently have</p>
  
  <pre><code>&lt;ul class="nav navbar-nav"&gt;
      &lt;li&gt;&lt;a href="{{ url('/') }}"&gt;Home&lt;/a&gt;&lt;/li&gt;
      @if (Auth::guest())
  
      @else
      &lt;li&gt;&lt;a href="{{ url('/admin') }}"&gt;Admin Dashboard&lt;/a&gt;&lt;/li&gt;
      @endif
  &lt;/ul&gt;
  </code></pre>
  
  <p>I have middleware set up on the admin route like so</p>
  
  <pre><code>Route::get('admin', ['middleware' =&gt; 'admin', 'uses' =&gt; 'AdminController@index']);
  </code></pre>
  
  <p>Which looks like</p>
  
  <pre><code>public function handle($request, Closure $next)
  {
      if ($request-&gt;user()-&gt;role != 1)
      {
          return redirect('home');
      }
  
      return $next($request);
  }
  </code></pre>
  
  <p>And that's fine, I just don't know how to get it to define a section of a blade template.</p>