title: Laravel: request->user() in boot() method on model (GlobalScope)
body: <p>I have some behaviour I cannot explain. I am in the middle of a rather big refactor and I bumped into an issue that has been in the code for a long time, but it seemed to work before the refactor.</p>
  
  <p>On some models <code>static::addGlobalScope</code> is used to extend some queries where needed. In this callback method the user that performs the request is fetched with <code>request()-&gt;user()</code>. This works inside the callback without issues, but when moved outside the callback this returns <code>null</code>. </p>
  
  <p>Working example:</p>
  
  <pre><code>protected static function boot()
  {
      parent::boot();
      static::addGlobalScope('auth', function (Builder $builder) {
          $user = request()-&gt;user();
  
          if ($user) {
              if ($user-&gt;role == 'consultant') {
                  $builder-&gt;where('user_id', $user-&gt;id);
              } elseif ($user-&gt;role == 'approver') {
                  $builder-&gt;whereHas('contract', function ($query) use ($user) {
                      return $query-&gt;whereHas('approvers', function ($query) use ($user) {
                          return $query-&gt;where('user_id', $user-&gt;id);
                      });
                  });
              }
          }
      });
  }
  </code></pre>
  
  <p>Example where <code>$user</code> is null. </p>
  
  <pre><code>protected static function boot()
  {
      parent::boot();
      $user = request()-&gt;user(); // Moved $user outside of the callback
  
      static::addGlobalScope('auth', function (Builder $builder) use ($user) {
          if ($user) {
              if ($user-&gt;role == 'consultant') {
                  $builder-&gt;where('user_id', $user-&gt;id);
              } elseif ($user-&gt;role == 'approver') {
                  $builder-&gt;whereHas('contract', function ($query) use ($user) {
                      return $query-&gt;whereHas('approvers', function ($query) use ($user) {
                          return $query-&gt;where('user_id', $user-&gt;id);
                      });
                  });
              }
          }
      });
  }
  </code></pre>
  
  <p>The second example has been taken from a model before the refactor.
  This method is being used on multiple models, this never gave any issues. Does anyone have an idea why <code>$user</code> is null when <code>request()-&gt;user()</code> is called outside of the callback in the <code>boot</code> method? And most important, why it never gave issues before?</p>