21 lines
428 B
PHP
21 lines
428 B
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Traits\Models;
|
||
|
|
|
||
|
|
use App\Models\Tenant;
|
||
|
|
|
||
|
|
trait IsRelatedToTenant
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Add a 'where' clause to the given query to scope to the current or first tenant.
|
||
|
|
*
|
||
|
|
* @return \Closure
|
||
|
|
*/
|
||
|
|
public static function whereTenantQuery(): \Closure
|
||
|
|
{
|
||
|
|
return function ($query) {
|
||
|
|
$query->where('tenant_id', \tenant()->getKey() ?? Tenant::first()->getKey());
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|