$devices * @param array $payload */ public function send(Collection $devices, array $payload): void { foreach ($devices->chunk(100) as $chunk) { $chunk = $chunk->values(); $response = Http::timeout(15)->acceptJson()->post(self::ENDPOINT, $chunk->map(fn (AppDevice $device) => [ 'to' => $device->push_token, 'title' => $payload['title'] ?? '', 'body' => $payload['body'] ?? '', 'data' => ['url' => $payload['url'] ?? '/'], 'sound' => 'default', ])->all()); if (! $response->successful()) { continue; } // Antwort in derselben Reihenfolge: abgemeldete Geräte entfernen foreach ((array) $response->json('data') as $i => $ticket) { $device = $chunk[$i] ?? null; if (! $device) { continue; } if (($ticket['status'] ?? null) === 'error' && ($ticket['details']['error'] ?? null) === 'DeviceNotRegistered') { $device->delete(); } elseif (($ticket['status'] ?? null) === 'ok') { $device->forceFill(['last_used_at' => now()])->save(); } } } } }