*/ public function toArray(Request $request): array { if (!$this->resource) { return []; } return [ 'customer' => [ 'fullname' => $this->fullname, 'email' => $this->email, 'phone' => $this->maskedPhone(), 'address' => $this->address, 'city' => $this->city, 'ward' => $this->ward->name ?? '', 'ward_code' => $this->ward_code, 'province' => $this->province->name ?? '', 'province_code' => $this->province_code, 'gender' => $this->gender?->value, 'gender_label' => $this->gender_label, 'birthday' => $this->birthday?->format('Y-m-d'), 'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null, 'company' => $this->company ?? '', 'avatar' => $this->avatar, 'cccd_updated' => (bool) ( $this->identity_number && $this->front_identity_number && $this->back_identity_number ), 'fb_link' => null, 'active_2fa' => (bool) $this->two_factor_enabled, 'off_mail_marketing' => (bool) $this->off_mail_marketing, 'email_marketing' => (bool) $this->email_marketing, 'receive_deposit' => (bool) $this->receive_deposit, 'is_recharge_zalo' => false, 'is_verify_telegram' => false, ], 'credit' => [ 'credit' => $this->credit, 'total' => $this->total, 'total_pending' => $this->total_pending ?? 0, 'point' => $this->point, 'point_used' => 0, 'point_total' => $this->point, ], 'service' => [ 'proxy' => 0, ...app(ServiceClientService::class)->countByType((int) $this->id), ] ]; } private function maskedPhone(): ?string { if (!$this->phone) { return null; } $visibleDigits = mb_substr($this->phone, -3); return str_repeat('*', max(0, mb_strlen($this->phone) - mb_strlen($visibleDigits))) . $visibleDigits; } }