title: Laravel: how to "disable" a global scope in order to include "inactive" objects into query?
body: <p>I am having trouble with global scopes, especially the removal of the scope.</p>
  
  <p>In my User model, i have a ActivatedUsersTrait, that introduces a global scope to only query for Users with the column "activated" set to true (The User is "activated" after email verification).</p>
  
  <p>So far everything works fine, when i query for User::all(), i only get Users with activated=true.</p>
  
  <p>My problem now is, how to include the non-activated Users into my query, like SoftDeletingTrait does via withTrashed()? This is only relevant in my ActivationController, where i need to get the User, set activated=true and save them back to db.</p>
  
  <p>I've created a withInactive() method in my ActiveUsersTrait, based on the method i found in SoftDeletingTrait, but when i run a query on User::withInactive->get(), the non-activated Users won't show up in the results.</p>
  
  <p>Here's my ActiveUsersTrait:
  
  
  <pre><code>use PB\Scopes\ActiveUsersScope;
  
  trait ActiveUsersTrait {
  
      public static function bootActiveUsersTrait()
      {
          static::addGlobalScope(new ActiveUsersScope);
      }
  
      public static function withInactive()
      {
          // dd(new static);
          return (new static)-&gt;newQueryWithoutScope(new ActiveUsersScope);
      }
  
      public function getActivatedColumn()
      {
          return 'activated';
      }
  
      public function getQualifiedActivatedColumn()
      {
          return $this-&gt;getTable().'.'.$this-&gt;getActivatedColumn();
      }
  
  }
  </code></pre>
  
  <p>and my ActiveUsersScope:</p>
  
  <p>
  
  <pre><code>use Illuminate\Database\Eloquent\ScopeInterface;
  use Illuminate\Database\Eloquent\Builder;
  
  class ActiveUsersScope implements ScopeInterface {
  
      public function apply(Builder $builder)
      {
          $model = $builder-&gt;getModel();
  
          $builder-&gt;where($model-&gt;getQualifiedActivatedColumn(), true);
  
      }
  
      public function remove(Builder $builder)
      {
          $column = $builder-&gt;getModel()-&gt;getQualifiedActivatedColumn();
  
          $query = $builder-&gt;getQuery();
  
          foreach ((array) $query-&gt;wheres as $key =&gt; $where)
          {
              if ($this-&gt;isActiveUsersConstraint($where, $column))
              {
                  unset($query-&gt;wheres[$key]);
  
                  $query-&gt;wheres = array_values($query-&gt;wheres);
              }
          }
      }
  
      protected function isActiveUsersConstraint(array $where, $column)
      {
          return $where['type'] == 'Basic' &amp;&amp; $where['column'] == $column;
      }
  }
  </code></pre>
  
  <p>Any help is highly appreciated!</p>
  
  <p>Thanks in advance! -Joseph</p>