Files
sam-api/app/Models/User.php

48 lines
1.2 KiB
PHP
Raw Normal View History

2025-07-17 10:05:47 +09:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
2025-07-17 10:05:47 +09:00
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Laravel\Sanctum\HasApiTokens;
use App\Traits\ModelTrait;
2025-07-17 10:05:47 +09:00
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'
];
2025-07-17 10:05:47 +09:00
public function userTenants()
{
return $this->hasMany(UserTenant::class);
}
2025-07-17 10:05:47 +09:00
public function userTenant() // 단일 기본 테넌트
{
// 예시: 첫 번째(기본) 테넌트 반환
return $this->hasOne(UserTenant::class)->where('is_active', 1);
}
2025-07-17 10:05:47 +09:00
public function userRoles()
2025-07-17 10:05:47 +09:00
{
return $this->hasMany(UserRole::class);
2025-07-17 10:05:47 +09:00
}
public function roles()
2025-07-17 10:05:47 +09:00
{
return $this->belongsToMany(Role::class, 'user_roles')
->withPivot('tenant_id', 'assigned_at');
2025-07-17 10:05:47 +09:00
}
public function userTenantById($tenantId)
{
return $this->hasOne(UserTenant::class)->where('tenant_id', $tenantId);
}
2025-07-17 10:05:47 +09:00
}