type = CompanyType::Company->value; $this->countryCode = (string) config('countries.default', 'DE'); } public function save(): void { try { $validated = $this->validate([ 'name' => ['required', 'string', 'max:255'], 'portal' => ['required', Rule::in([ Portal::Presseecho->value, Portal::Businessportal24->value, Portal::Both->value, ])], 'type' => ['required', Rule::in([CompanyType::Company->value, CompanyType::Agency->value])], 'address' => ['nullable', 'string', 'max:1000'], 'email' => ['nullable', 'email', 'max:190'], 'phone' => ['nullable', 'string', 'max:40'], 'website' => ['nullable', 'url', 'max:190'], 'countryCode' => ['nullable', 'string', 'size:2', Rule::in(array_keys((array) config('countries.items', [])))], ]); } catch (ValidationException $e) { $count = array_sum(array_map('count', $e->errors())); Flux::toast( heading: __('Bitte Eingaben prüfen'), text: $count > 1 ? __(':count Felder benötigen deine Aufmerksamkeit.', ['count' => $count]) : __('Ein Feld benötigt deine Aufmerksamkeit.'), variant: 'danger', duration: 6000, ); throw $e; } $user = auth()->user(); $company = new Company([ 'portal' => $validated['portal'], 'owner_user_id' => $user->id, 'type' => $validated['type'], 'name' => $validated['name'], 'address' => $validated['address'] ?: null, 'country_code' => $validated['countryCode'] ?: null, 'email' => $validated['email'] ?: null, 'phone' => $validated['phone'] ?: null, 'website' => $validated['website'] ?: null, 'is_active' => true, 'disable_footer_code' => $this->disableFooterCode, ]); $company->slug = $company->generateUniqueSlug($validated['name'], [ 'portal' => $validated['portal'], ]); $company->save(); $user->companies()->syncWithoutDetaching([ $company->id => ['role' => 'owner'], ]); Flux::toast( heading: __('Firma angelegt'), text: __('„:name" wurde angelegt und steht sofort zur Verfügung.', ['name' => $company->name]), variant: 'success', ); $this->redirect(route('me.press-kits.show', $company->id), navigate: true); } public function with(): array { return [ 'portals' => [ Portal::Presseecho->value => Portal::Presseecho->label(), Portal::Businessportal24->value => Portal::Businessportal24->label(), Portal::Both->value => Portal::Both->label(), ], 'types' => [ CompanyType::Company->value => CompanyType::Company->label(), CompanyType::Agency->value => CompanyType::Agency->label(), ], 'countries' => (array) config('countries.items', []), ]; } }; ?>
{{-- ============== PAGE HEADER ============== --}}
{{ __('Stammdaten') }}
@foreach ($portals as $value => $label) {{ $label }} @endforeach @foreach ($types as $value => $label) {{ $label }} @endforeach @foreach ($countries as $code => $countryName) {{ $countryName }} @endforeach
{{ __('Abbrechen') }} {{ __('Firma anlegen') }}