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

54 lines
1.3 KiB
PHP
Raw Normal View History

2025-07-17 10:05:47 +09:00
<?php
namespace App\Models\Members;
2025-07-17 10:05:47 +09:00
2025-07-29 13:00:25 +09:00
use App\Models\Commons\Role;
use App\Models\File;
2025-07-29 13:00:25 +09:00
use App\Traits\ModelTrait;
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\Sanctum\HasApiTokens;
class User extends Authenticatable
{
2025-07-28 12:57:08 +09:00
use HasApiTokens, Notifiable, 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-29 13:00:25 +09:00
public function files()
{
return $this->morphMany(File::class, 'fileable');
}
2025-07-17 10:05:47 +09:00
}