title: Accessing user database info within a view in Laravel
body: <p>I'm trying to create a dynamic navigation bar on my Laravel project, that, if the user is logged in, outputs <code>Hello, {{$user-&gt;name}}!</code>.</p>
  
  <p>This, however, is not working.</p>
  
  <p>If I try to add that <code>$user-&gt;name</code> variable to my navbar <code>layout</code> I simply get the following error: <code>Undefined variable: user (View: C:\xampp\htdocs\laravel\app\views\layout\navbar.blade.php)</code>.</p>
  
  <p>This <code>layout</code> is included in the main <code>layout</code> like so: <code>@include('layout.navbar')</code> and the code is as follows:</p>
  
  <pre><code>&lt;nav class="navbar navbar-default"&gt;
      &lt;div class="container-fluid"&gt;
          &lt;div class="navbar-header"&gt;
              &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"&gt;
                  &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
                  &lt;span class="icon-bar"&gt;&lt;/span&gt;
              &lt;/button&gt;
              &lt;a class="navbar-brand" id="logo" href="{{URL::route('home')}}"&gt;asd&lt;/a&gt;
              &lt;ul class="nav navbar-nav"&gt;
                  @if(Auth::check())
                  &lt;li&gt;
                      &lt;a&gt;Hello, {{$user-&gt;name}}!&lt;/a&gt;
                  &lt;/li&gt;
                  @endif
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
              &lt;ul class="nav navbar-nav navbar-right"&gt;
                  @if(Auth::check())
                  &lt;li&gt;
                      &lt;a href="{{URL::route('profile', $user-&gt;name)}}"&gt;Profile&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;a href="{{URL::route('account-logout')}}"&gt;Logout&lt;/a&gt;
                  &lt;/li&gt;                
                  @else
                  &lt;li&gt;
                      &lt;a href="{{URL::route('account-login')}}"&gt;Login&lt;/a&gt;
                  &lt;/li&gt;
                  &lt;li&gt;
                      &lt;a href="{{URL::route('account-create')}}"&gt;Register&lt;/a&gt;
                  &lt;/li&gt;                
                  @endif
              &lt;/ul&gt;
          &lt;/div&gt;&lt;!-- /.navbar-collapse --&gt;
      &lt;/div&gt;&lt;!-- /.container-fluid --&gt;
  &lt;/nav&gt;
  </code></pre>
  
  <p>What is the correct way to access a user object (with the information of the user that is currently logged in) within this context?</p>