HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux Bradford-Sitios 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: www-data (33)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api_matriculas/app/Http/Resources/ParentResource.php
<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class ParentResource extends JsonResource
{
    protected $allData;

    public function __construct($resource, $allData = true)
    {
        parent::__construct($resource);
        $this->allData = $allData;
    }

    public function toArray($request)
    {
        $documentType = $this->document_type ?? 'RUT';
        $isPassport = $documentType === 'PASSPORT';

        $data = [
            'id'              => $this->id,
            'document_type'   => $documentType,
            'rut'             => $this->rut,
            'rut_formatted'   => ($isPassport || empty($this->rut)) ? ($this->rut ?? '') : formatterRut($this->rut, true),
            'first_name'      => $this->first_name,
            'second_name'     => $this->second_name,
            'last_name'       => $this->last_name,
            'second_last_name' => $this->second_last_name,
            'email'           => $this->email,
            'mobile'          => $this->mobile,
            'home_phone'      => $this->home_phone,
            'work_phone'      => $this->work_phone,
            'birth_date'      => $this->birth_date,
            'address'         => $this->address,
            'profession'      => $this->profession,
        ];

        $data['relationship'] = $this->relationship_id > 0 ? [
            'id'   => $this->relationship->id,
            'name' => $this->relationship->relationship,
        ] : null;

        $data['gender'] = $this->gender_id > 0 ? [
            'id'   => $this->gender->id,
            'name' => $this->gender->gender,
        ] : null;

        $data['country'] = $this->country_id > 0 ? [
            'id'   => $this->country->id,
            'name' => $this->country->country,
        ] : null;

        $data['region'] = $this->region_id > 0 ? [
            'id'        => $this->region->id,
            'region'    => $this->region->region,
            'long_name' => $this->region->long_name,
        ] : null;

        $data['commune'] = $this->commune_id > 0 ? [
            'id'      => $this->commune->id,
            'commune' => $this->commune->commune,
        ] : null;

        if ($this->allData) {
            $data['username']     = $this->user_id > 0 ? $this->user->username : null;
            $data['status']       = $this->status;
            $data['created_at']   = sort_datetimeHuman($this->created_at);
            $data['updated_at']   = sort_datetimeHuman($this->updated_at);
            $data['user_created'] = $this->user_created > 0 ? $this->createdBy->username : null;
            $data['user_updated'] = $this->user_updated > 0 ? $this->updatedBy->username : null;
        }

        return $data;
    }
}