title: PHP laravel middleware in boot()
body: <p>In my project I am using Laravel 5.2 and now I'm stuck at this little problem I cant figure out how to fix.</p>
  
  <p>I need to share a variable, only with signed users, on all views.
  I know I need to use <code>view() -&gt; composer()</code> to do this, but how? </p>
  
  <p>Where would the code go? I can't use it in the AppServiceProvider since the <code>boot()</code> method is run before the session is started. I have seen someone recomend using middleware to do what I'm trying to do, but I cant figure out that either. 
  Where would i write this new middleware? Where would i then use <code>view() -&gt; composer()</code>?</p>
  
  <p>A little more detail:
  I'm, trying to check for friend requests, and put that in the users sidebar on every view if there are any requests.</p>
  
  <p>And my view composer looks like this in the <code>boot()</code> method, but does not work because of <code>Auth::check()</code></p>
  
  <pre><code>    if (Auth::check()) {
  
          view() -&gt; composer('*', function($view) {
  
              // Check for friend requests
              $friend_requests = DB::table('friends')
                  -&gt; where('user_id_receiver', '=', Auth::user() -&gt; id)
                  -&gt; where (function($query) {
                      $query -&gt; where('status', '=', 2);
                  })
                  -&gt; get();
  
              $view -&gt; with('friend_requests', $friend_requests);
  
          });
  
      }
  </code></pre>
  
  <p>My blade layout is also pretty simple, just using extends and includes for sidebar and other stuff.</p>
  
  <p>If I need to clarify something, please tell.
  Thanks in advance.</p>