48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Fortify\TwoFactorAuthenticatable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use App\Traits\ModelTrait;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, Notifiable, TwoFactorAuthenticatable, SoftDeletes, ModelTrait;
|
|
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'
|
|
];
|
|
|
|
public function userTenants()
|
|
{
|
|
return $this->hasMany(UserTenant::class);
|
|
}
|
|
|
|
public function userTenant() // 단일 기본 테넌트
|
|
{
|
|
// 예시: 첫 번째(기본) 테넌트 반환
|
|
return $this->hasOne(UserTenant::class)->where('is_active', 1);
|
|
}
|
|
|
|
public function userRoles()
|
|
{
|
|
return $this->hasMany(UserRole::class);
|
|
}
|
|
|
|
public function roles()
|
|
{
|
|
return $this->belongsToMany(Role::class, 'user_roles')
|
|
->withPivot('tenant_id', 'assigned_at');
|
|
}
|
|
|
|
public function userTenantById($tenantId)
|
|
{
|
|
return $this->hasOne(UserTenant::class)->where('tenant_id', $tenantId);
|
|
}
|
|
}
|