title: Laravel: Check if the field was filled in the route, using Trait and Scope
body: <p>I have an api that I am implementing multi-tenant based on an additional column in the tables.</p>
  <p>For this I created a trait that implements a
  static::addGlobalScope() and static::creating().</p>
  <p>I have a user_idXtenant_id table. In this table I store the accesses that the user has.</p>
  <p>My Route looks like this:</p>
  <pre><code>Route::get('{tenant_id}/products', function ($tenant_id) {
          return App\Products::where(['tenant_id' =&gt; $tenant_id])-&gt;get();
      })-&gt;middleware('role_or_permission:admin|seller|get-products');
  
  Route::get('products', function () {
          return App\Products::get();
      })-&gt;middleware('role_or_permission:admin|seller|get-products');
  </code></pre>
  <p>The idea is that in the first route it is verified if the user has access to tenant_id and if he has access, return only the products of that tenant_id (here Polices can be useful and solve the problem).</p>
  <p>The second route, on the other hand, must return all products of all tenant_id that the user has access to. For this, I use static :: addGlobalScope() to set the tenants that the user has access to in this way:</p>
  <pre><code>$builder-&gt;whereIn('tenant_id', $tenants);
  </code></pre>
  <p>The question is how to check in GlobalScope if tenant_id was filled in the model. So, if it is present, I only check the permission and if it is not present I include the tenant_id that the user has access to.</p>
  <p>I hope I have been able to adequately exemplify the problem.</p>
  <p>Any help is most welcome.</p>
  <p>Thank you!</p>