> */ protected function promptForMissingArgumentsUsing(): array { return [ 'bank' => ['Which bank UUID should the logo be set for?', 'E.g. 01234567-89ab-cdef-0123-456789abcdef'], 'url' => ['What is the image URL to download?', 'E.g. https://example.com/logo.png'], ]; } public function handle(): int { $bank = Bank::query()->find($this->argument('bank')); if ($bank === null) { $this->error("Bank not found: {$this->argument('bank')}"); return self::FAILURE; } $url = $this->argument('url'); try { $response = Http::timeout(30)->get($url); } catch (ConnectionException $e) { $this->error("Failed to connect to URL: {$e->getMessage()}"); return self::FAILURE; } if ($response->failed()) { $this->error("Failed to download image: HTTP {$response->status()}"); return self::FAILURE; } $contentType = strtolower((string) $response->header('Content-Type')); if (! str_starts_with($contentType, 'image/')) { $this->error("URL does not point to an image (Content-Type: {$contentType})."); return self::FAILURE; } try { $manager = new ImageManager(new Driver); $image = $manager->read($response->body()); } catch (\Exception $e) { $this->error("Downloaded file is not a valid image: {$e->getMessage()}"); return self::FAILURE; } if ($image->width() !== $image->height()) { $this->error("Image is not square ({$image->width()}×{$image->height()}) — skipping."); return self::FAILURE; } $originalSize = $image->width(); $this->info("Image downloaded ({$originalSize}×{$originalSize}px)."); if ($image->width() > 250) { $image->scaleDown(250, 250); $this->info("Resized to {$image->width()}×{$image->height()}px."); } $path = "banks/logos/{$bank->id}.png"; Storage::disk('public')->put($path, $image->toPng()->toString()); $logoUrl = Storage::disk('public')->url($path); $bank->update(['logo' => $logoUrl]); $this->info("Logo updated for \"{$bank->name}\"."); $this->info("Stored at: {$logoUrl}"); return self::SUCCESS; } }