Files
sam-manage/app/Models/HR/Position.php
김보곤 29ca022321 feat: [hr] 인사관리 사원관리 Phase 1 구현
- Employee, Position 모델 생성 (tenant_user_profiles, positions 테이블)
- EmployeeService 생성 (CRUD, 통계, 필터/검색/페이지네이션)
- 뷰 컨트롤러(HR/EmployeeController) + API 컨트롤러 생성
- Blade 뷰: index(통계카드+HTMX테이블), create, edit, show, partials/table
- 라우트: web.php(/hr/employees/*), api.php(/admin/hr/employees/*)
2026-02-26 18:40:01 +09:00

62 lines
1.3 KiB
PHP

<?php
namespace App\Models\HR;
use App\Traits\ModelTrait;
use Illuminate\Database\Eloquent\Model;
class Position extends Model
{
use ModelTrait;
protected $table = 'positions';
protected $fillable = [
'tenant_id',
'type',
'key',
'name',
'sort_order',
'is_active',
];
protected $casts = [
'tenant_id' => 'int',
'sort_order' => 'int',
'is_active' => 'bool',
];
public const TYPE_RANK = 'rank';
public const TYPE_TITLE = 'title';
// =========================================================================
// 스코프
// =========================================================================
public function scopeForTenant($query, ?int $tenantId = null)
{
$tenantId = $tenantId ?? session('selected_tenant_id');
if ($tenantId) {
return $query->where('tenant_id', $tenantId);
}
return $query;
}
public function scopeRanks($query)
{
return $query->where('type', self::TYPE_RANK);
}
public function scopeTitles($query)
{
return $query->where('type', self::TYPE_TITLE);
}
public function scopeOrdered($query)
{
return $query->orderBy('sort_order');
}
}