$ips */ public function __construct( public readonly string $type, public readonly string $clientName, public readonly array $ips, public readonly string $date, public readonly ?string $note = null, public readonly ?string $subjectOverride = null, public readonly array $storedFiles = [], ) {} /** * @param iterable $pools * @return array */ public static function ipsFrom(iterable $pools): array { return collect($pools) ->map(fn (IpPool $pool) => $pool->only(['ip_address', 'cidr', 'gateway', 'service_name'])) ->values() ->all(); } public function attachments(): array { return $this->storedFileAttachments($this->storedFiles); } public function envelope(): Envelope { $envelope = parent::envelope(); if (filled($this->subjectOverride)) { $envelope->subject = trim($this->subjectOverride); } return $envelope; } protected function scenario(): string { return $this->type; } protected function variables(): array { $carbon = Carbon::parse($this->date); $date = $carbon->format('d/m/Y'); return [ 'client_name' => $this->clientName, 'ip_count' => (string) count($this->ips), 'ip_rows' => collect($this->ips)->map(fn (array $ip) => EmailTemplateShell::row( e($ip['ip_address']), e(implode(' · ', array_filter([ $ip['cidr'] ? '/' . $ip['cidr'] : null, $ip['gateway'] ? 'Gateway ' . $ip['gateway'] : null, ])) ?: '—'), ))->implode(''), 'ip_table' => $this->ipTable($date), 'issued_on' => "ngày {$carbon->day} tháng {$carbon->month} năm {$carbon->year}", 'allocated_at' => $date, 'revoked_at' => $date, 'note_block' => $this->note ? EmailTemplateShell::note(nl2br(e($this->note)), 'Ghi chú:') : '', ]; } private function ipTable(string $date): string { $last = count($this->ips) - 1; $rows = collect($this->ips)->values()->map(function (array $ip, int $index) use ($date, $last) { $border = $index === $last ? '' : ' border-bottom: 1px solid #f6d2b8;'; $cell = fn (string $value, string $extra = '') => '' . $value . ''; return '' . $cell((string) ($index + 1), ' width: 60px;') . $cell(e($ip['ip_address']), " font-family: Consolas, 'Courier New', monospace; font-weight: bold; color: #c2410c;") . $cell(e($ip['service_name'] ?: '—')) . $cell($date) . ''; })->implode(''); $head = collect(['STT', 'IP Address', 'Dịch vụ', 'Ngày cấp phát']) ->map(fn (string $title) => '' . $title . '') ->implode(''); return '' . '' . $head . '' . $rows . '
'; } }