*/ protected $fillable = [ 'user_id', 'name', 'email', 'phone', 'password', 'options', 'profile_photo_path', 'role', 'is_active', 'is_super_admin', ]; /** * The attributes that should be hidden for serialization. * * @var list */ protected $hidden = [ 'password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at', 'deleted_at', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'last_login_at' => 'datetime', 'password' => 'hashed', 'options' => 'array', 'is_active' => 'boolean', 'is_super_admin' => 'boolean', ]; } /** * 관계: 테넌트들 (Many-to-Many via user_tenants) */ public function tenants(): BelongsToMany { return $this->belongsToMany(\App\Models\Tenants\Tenant::class, 'user_tenants') ->withTimestamps() ->withPivot(['is_active', 'is_default', 'joined_at', 'left_at']); } /** * 현재 선택된 테넌트 (세션 기반) */ public function currentTenant() { $tenantId = session('selected_tenant_id'); if (! $tenantId) { return $this->tenants()->where('is_default', true)->first() ?? $this->tenants()->first(); } return $this->tenants()->find($tenantId); } }