ldc-com-app-bo/app/Traits/Models/IsRelatedToTenant.php
2025-06-17 12:29:15 +02:00

20 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());
};
}
}