- Material 모델 - fillable 속성 추가 (모든 필드 명시) - User 모델 - BelongsToMany 관계 타입 힌트 추가 - Product 모델 - fillable에 unit 필드 추가 - casts 순서 정리 (boolean 그룹화) - ProductComponent 모델 - quantity 캐스트 정밀도 변경 (decimal:4 → decimal:6) - referencedItem() 메서드 추가 (동적 관계 로드) - product(), material() 관계 메서드 수정 (where 조건 추가) - is_default 캐스트 제거 (컬럼 없음) - Tenant 모델 - options 캐스트 추가 (array) - scopeActive() 추가 (trial, active 상태 필터링) - isActive(), isTrial() 헬퍼 메서드 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.1 KiB
PHP
81 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Members;
|
|
|
|
use App\Models\Commons\File;
|
|
use App\Models\Tenants\Tenant;
|
|
use App\Traits\ModelTrait;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
/**
|
|
* @mixin IdeHelperUser
|
|
*/
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, Notifiable, SoftDeletes, ModelTrait, HasRoles;
|
|
|
|
protected $guard_name = 'api'; // ★ 중요: 권한/역할 가드 통일
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'name',
|
|
'email',
|
|
'phone',
|
|
'password',
|
|
'options',
|
|
'profile_photo_path',
|
|
];
|
|
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'last_login_at' => 'datetime',
|
|
'options' => 'array',
|
|
'deleted_at' => 'datetime',
|
|
'password' => 'hashed', // ← 이걸 쓰면 자동 해싱
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password', 'remember_token',
|
|
'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at',
|
|
'deleted_at',
|
|
];
|
|
|
|
public function userTenants()
|
|
{
|
|
return $this->hasMany(UserTenant::class);
|
|
}
|
|
|
|
public function userTenant()
|
|
{
|
|
return $this->hasOne(UserTenant::class)->where('is_default', 1);
|
|
}
|
|
|
|
public function userRoles()
|
|
{
|
|
return $this->hasMany(UserRole::class);
|
|
}
|
|
|
|
public function userTenantById($tenantId)
|
|
{
|
|
return $this->hasOne(UserTenant::class)->where('tenant_id', $tenantId);
|
|
}
|
|
|
|
public function files()
|
|
{
|
|
return $this->morphMany(File::class, 'fileable');
|
|
}
|
|
|
|
public function tenantsMembership(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Tenant::class, 'user_tenants', 'user_id', 'tenant_id')
|
|
->as('membership') // pivot 대신 membership으로 표기
|
|
->withPivot(['is_active', 'is_default', 'joined_at', 'left_at', 'deleted_at'])
|
|
->wherePivotNull('deleted_at'); // 소프트삭제 제외
|
|
}
|
|
}
|