nyavokevin 56b0c50111 feat(auth): add employee user linking and password setup flow
Add user management endpoints and link employees to existing users
through `user_id`, including API resources, validation, repository
support, and database migrations.

Introduce a two-step login flow that checks email first and lets users
without a password create one before signing in.

Update the employee detail UI with a dedicated user tab and refresh the
employee and intervention side navigation to support the new account
management flow.
2026-04-08 13:31:57 +03:00

48 lines
1.5 KiB
PHP

<?php
namespace App\Http\Resources\Employee;
use Illuminate\Http\Resources\Json\JsonResource;
class EmployeeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'full_name' => $this->full_name,
'email' => $this->email,
'phone' => $this->phone,
'user_id' => $this->user_id,
'job_title' => $this->job_title,
'hire_date' => $this->hire_date?->format('Y-m-d'),
'active' => $this->active,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
// Relations
'thanatopractitioner' => $this->when(
$this->relationLoaded('thanatopractitioner'),
new ThanatopractitionerResource($this->thanatopractitioner)
),
'user' => $this->when(
$this->relationLoaded('user') && $this->user,
fn () => [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
'employee_id' => $this->id,
]
),
];
}
}