title: How to share Auth::user among all views in Laravel 5?
body: <p>I need to share the currently logged in user to all views. I am attempting to use the <code>view-&gt;share()</code> method within <code>AppServiceProvider.php</code> file. </p>
  
  <p>I have the following:</p>
  
  <pre><code>&lt;?php namespace App\Providers;
  
  use Illuminate\Support\ServiceProvider;
  
  use Illuminate\Contracts\Auth\Guard;
  
  
  class AppServiceProvider extends ServiceProvider {
  
  
      public function boot(Guard $guard)
      {
          view()-&gt;share('guard', $guard);
          view()-&gt;share('user', $guard-&gt;user());
      }
  
      //..
  }
  </code></pre>
  
  <p>However, when I hit up a view (after logging in), the <code>user</code> variable is null. Strangely, the <code>$guard-&gt;user</code> (the protected attribute, not the public method user()) is not. The output I get is the following:</p>
  
  <p><img src="https://i.stack.imgur.com/9L3hI.png" alt="enter image description here"></p>
  
  <p>Note the guard->user variable is populated, but the user variable is null. </p>