Files

61 lines
2.0 KiB
PHP

<?php
namespace App\Http\Resources\Api\Client;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClientResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if (!$this->resource) {
return [];
}
return [
'customer' => [
'fullname' => $this->fullname,
'email' => $this->email,
'phone' => $this->phone,
'address' => $this->address,
'city' => $this->city,
'ward' => $this->ward->name ?? '',
'province' => $this->province->name ?? '',
'gender' => $this->gender_label,
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
'company' => $this->company ?? '',
'avatar' => $this->avatar,
'cmnd_after' => $this->front_identity_number,
'cmnd_before' => $this->back_identity_number,
'cmnd' => $this->identity_number,
'fb_link' => null,
'active_2fa' => 0,
'off_mail_marketing' => $this->off_mail_marketing,
'is_recharge_zalo' => 0,
'is_verify_telegram' => 0,
],
'credit' => [
'credit' => $this->credit,
'total' => $this->total,
'total_pending' => $this->total_pending ?? 0,
'point' => $this->point,
'point_used' => 0,
'point_total' => $this->point,
],
'service' => [
'vps' => $this->vps_count ?? $this->vps()->count(),
'proxy' => 0,
'server' => 0,
'hosting' => $this->hosting_count ?? $this->hosting()->count(),
'domain' => $this->domain_count ?? $this->domain()->count(),
]
];
}
}