Initial commit device-management
tests / ci (push) Has been cancelled

This commit is contained in:
Wian Drs
2026-08-25 09:42:00 +07:00
commit 1e80be180e
1159 changed files with 149545 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
namespace App\Models\Concerns;
use App\Models\Tenant;
use App\Support\TenantContext;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
trait BelongsToTenant
{
protected static function bootBelongsToTenant(): void
{
static::addGlobalScope('tenant', function (Builder $builder): void {
$tenantId = app(TenantContext::class)->id();
if ($tenantId !== null) {
$builder->where($builder->qualifyColumn('tenant_id'), $tenantId);
}
});
static::creating(function (self $model): void {
$tenantId = app(TenantContext::class)->id();
if ($tenantId !== null && $model->getAttribute('tenant_id') === null) {
$model->setAttribute('tenant_id', $tenantId);
}
});
}
public function tenant(): BelongsTo
{
return $this->belongsTo(Tenant::class);
}
}