Files
sam-api/app/Models/Production/WorkOrderAssignee.php

65 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace App\Models\Production;
use App\Models\Members\User;
use App\Traits\BelongsToTenant;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 작업지시 담당자 피벗 모델
*
* 다중 담당자 지원을 위한 피벗 테이블 모델
*/
class WorkOrderAssignee extends Model
{
use BelongsToTenant, ModelTrait;
protected $table = 'work_order_assignees';
protected $fillable = [
'tenant_id',
'work_order_id',
'user_id',
'is_primary',
];
protected $casts = [
'is_primary' => 'boolean',
];
// ──────────────────────────────────────────────────────────────
// 관계
// ──────────────────────────────────────────────────────────────
/**
* 작업지시
*/
public function workOrder(): BelongsTo
{
return $this->belongsTo(WorkOrder::class);
}
/**
* 담당자
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
// ──────────────────────────────────────────────────────────────
// 스코프
// ──────────────────────────────────────────────────────────────
/**
* 담당자만
*/
public function scopePrimary($query)
{
return $query->where('is_primary', true);
}
}