user()->tokenCan('press-releases:write'), 403); try { $validated = $request->validate([ 'company' => ['required', 'array'], 'company.name' => ['required', 'string', 'max:255'], 'company.portal' => ['nullable', Rule::enum(Portal::class)->only([Portal::Presseecho, Portal::Businessportal24])], 'company.address' => ['nullable', 'string', 'max:1000'], 'company.country_id' => ['nullable', 'integer'], 'company.phone' => ['nullable', 'string', 'max:100'], 'company.fax' => ['nullable', 'string', 'max:100'], 'company.email' => ['nullable', 'email', 'max:255'], 'company.website' => ['nullable', 'string', 'max:255'], ])['company']; } catch (ValidationException $exception) { return $this->legacyValidationError($exception); } $user = $request->user(); // Portal aus Parameter/Domain, sonst wie bisher vom User — der // User-Fallback allein ließ alle Firmen (und damit deren PMs) von // Kunden mit Keys beider Altportale im selben Portal landen. $company = new Company([ 'portal' => $this->resolveRequestedPortal( $validated['portal'] ?? null, $user->portal, )->value, 'type' => CompanyType::Company->value, 'name' => $validated['name'], 'address' => $validated['address'] ?? null, 'country_code' => $this->legacyCountryCode($validated['country_id'] ?? null), 'phone' => $validated['phone'] ?? null, 'fax' => $validated['fax'] ?? null, 'email' => $validated['email'] ?? null, 'website' => $validated['website'] ?? null, // Alt-Verhalten: per API angelegte Firmen waren sofort nutzbar. 'is_active' => true, ]); $company->owner_user_id = $user->id; $company->slug = $company->generateUniqueSlug($company->name); $company->save(); $company->users()->attach($user->id, ['role' => 'owner']); return $this->legacyCreated(url("/service/users/me/companies/{$company->id}")); } }