2026-01-11 23:29:32 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-01-29 15:33:54 +09:00
|
|
|
use App\Traits\Auditable;
|
2026-01-11 23:29:32 +09:00
|
|
|
use App\Traits\BelongsToTenant;
|
|
|
|
|
use App\Traits\ModelTrait;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
|
|
|
|
|
|
class Labor extends Model
|
|
|
|
|
{
|
2026-01-29 15:33:54 +09:00
|
|
|
use Auditable, BelongsToTenant, ModelTrait, SoftDeletes;
|
2026-01-11 23:29:32 +09:00
|
|
|
|
|
|
|
|
protected $table = 'labors';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'tenant_id',
|
|
|
|
|
'labor_number',
|
|
|
|
|
'category',
|
|
|
|
|
'min_m',
|
|
|
|
|
'max_m',
|
|
|
|
|
'labor_price',
|
|
|
|
|
'status',
|
|
|
|
|
'is_active',
|
|
|
|
|
'created_by',
|
|
|
|
|
'updated_by',
|
|
|
|
|
'deleted_by',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'min_m' => 'decimal:2',
|
|
|
|
|
'max_m' => 'decimal:2',
|
|
|
|
|
'labor_price' => 'integer',
|
|
|
|
|
'is_active' => 'boolean',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 상태별 필터 Scope
|
|
|
|
|
*/
|
|
|
|
|
public function scopeByStatus($query, string $status)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', $status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 구분별 필터 Scope
|
|
|
|
|
*/
|
|
|
|
|
public function scopeByCategory($query, string $category)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('category', $category);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 검색 Scope
|
|
|
|
|
*/
|
|
|
|
|
public function scopeSearch($query, ?string $search)
|
|
|
|
|
{
|
|
|
|
|
if (empty($search)) {
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $query->where(function ($q) use ($search) {
|
|
|
|
|
$q->where('labor_number', 'like', "%{$search}%")
|
2026-01-16 21:59:06 +09:00
|
|
|
->orWhere('category', 'like', "%{$search}%");
|
2026-01-11 23:29:32 +09:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|