Files
kulakpos_web/Modules/HrmAddon/App/Models/Leave.php
eko54r 3e1b64e008
Some checks failed
Build, Push and Deploy / build-and-push (push) Failing after 3m30s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 15s
Build, Push and Deploy / deploy-staging (push) Has been skipped
Build, Push and Deploy / deploy-production (push) Has been skipped
update addon HRM
2026-05-04 23:04:09 +07:00

57 lines
1.4 KiB
PHP

<?php
namespace Modules\HrmAddon\App\Models;
use App\Models\Branch;
use App\Models\Scopes\BranchScope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Leave extends Model
{
use HasFactory;
protected $fillable = ['business_id', 'branch_id', 'employee_id', 'leave_type_id', 'department_id', 'start_date', 'end_date', 'leave_duration', 'month', 'status', 'description'];
public function branch(): BelongsTo
{
return $this->belongsTo(Branch::class)->withTrashed();
}
protected static function booted()
{
static::addGlobalScope(new BranchScope);
if (auth()->check() && auth()->user()->accessToMultiBranch()) {
static::addGlobalScope('withBranch', function ($builder) {
$builder->with('branch:id,name');
});
}
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->branch_id = auth()->user()->branch_id ?? auth()->user()->active_branch_id;
});
}
public function employee()
{
return $this->belongsTo(Employee::class);
}
public function leave_type()
{
return $this->belongsTo(LeaveType::class);
}
public function department()
{
return $this->belongsTo(Department::class);
}
}