Files
hr/app/Services/Employee/EmployeeService.php
2026-07-30 17:24:40 +05:00

49 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services\Employee;
use App\Enums\EmploymentStatus;
use App\Models\Employee;
use App\Models\User;
use App\Notifications\EmployeeTerminatedNotification;
use Carbon\Carbon;
use Illuminate\Support\Facades\Notification;
class EmployeeService
{
/**
* @param array<string, mixed> $data
*/
public function create(array $data): Employee
{
return Employee::create($data);
}
/**
* @param array<string, mixed> $data
*/
public function update(Employee $employee, array $data): Employee
{
$employee->update($data);
return $employee->refresh();
}
public function terminate(Employee $employee, ?Carbon $date = null): Employee
{
$employee->update([
'employment_status' => EmploymentStatus::Terminated,
'termination_date' => $date ?? now(),
]);
Notification::send(
User::role('hr_manager')->get(),
new EmployeeTerminatedNotification($employee),
);
return $employee->refresh();
}
}