value.','.Portal::Businessportal24->value)] public string $portal = Portal::Presseecho->value; #[Validate('required|min:3|max:255')] public string $company_name = ''; #[Validate('nullable|max:500')] public string $description = ''; #[Validate('required|email')] public string $email = ''; #[Validate('nullable|max:50')] public string $phone = ''; #[Validate('nullable|url')] public string $website = ''; #[Validate('nullable|max:255')] public string $street = ''; #[Validate('nullable|max:20')] public string $zip = ''; #[Validate('nullable|max:255')] public string $city = ''; #[Validate('nullable|max:255')] public string $state = ''; #[Validate('required|max:2')] public string $country = 'DE'; #[Validate('nullable|image|max:4096')] public $logo; #[Validate('nullable|max:255')] public ?string $tax_id = null; #[Validate('nullable|max:255')] public ?string $registration_number = null; public bool $is_verified = false; public bool $is_active = true; public function save(ImageService $imageService): void { $this->authorize('companies:write'); $this->validate(); $slug = (new Company)->generateUniqueSlug($this->company_name, ['portal' => $this->portal]); $company = Company::query()->create([ 'portal' => $this->portal, // Firmen sind ausschließlich Newsrooms; der Übermittler // („Agentur") ist eine Profil-Eigenschaft des Accounts. 'type' => CompanyType::Company->value, 'name' => $this->company_name, 'slug' => $slug, 'address' => $this->composeAddress(), 'country_code' => strtoupper($this->country), 'phone' => $this->phone ?: null, 'email' => $this->email ?: null, 'website' => $this->website ?: null, 'is_active' => $this->is_active, ]); // Logo wie im Edit-Pfad über den ImageService (Mime-Whitelist ohne // SVG, Re-Encode via GD, UUID-Name) — nie roh auf die public-Disk. if ($this->logo) { $stored = $imageService->storeCompanyLogo( $this->logo, $this->portal, $company->id, ); $company->update([ 'logo_path' => $stored['path'], 'logo_variants' => $stored['variants'], ]); } session()->flash('success', 'Firma erfolgreich erstellt.'); $this->redirect(route('admin.companies.index'), navigate: true); } public function with(): array { return [ 'countries' => collect([ ['code' => 'DE', 'name' => 'Deutschland'], ['code' => 'AT', 'name' => 'Österreich'], ['code' => 'CH', 'name' => 'Schweiz'], ['code' => 'FR', 'name' => 'Frankreich'], ['code' => 'GB', 'name' => 'Großbritannien'], ['code' => 'US', 'name' => 'USA'], ]), // „Beide Portale" ist bei der Anlage nicht wählbar, damit neue // Firmen ihre PMs nicht automatisch auf beiden Portalen // veröffentlichen. 'portalOptions' => array_filter( Portal::cases(), fn (Portal $portalCase): bool => $portalCase !== Portal::Both, ), ]; } protected function composeAddress(): ?string { $lineOne = trim($this->street); $lineTwo = trim(trim($this->zip).' '.trim($this->city)); $lineThree = trim($this->state); $parts = array_filter([$lineOne, $lineTwo, $lineThree], fn ($value) => $value !== ''); return $parts !== [] ? implode(', ', $parts) : null; } }; ?>