user()->tokenCan('press-releases:write'), 403); $company = Company::withoutGlobalScopes() ->whereKey($company) ->accessibleBy($request->user()) ->first(); if (! $company) { return $this->legacyError(403, ['You may only access companies which are related to your user-account']); } try { $validated = $request->validate([ 'contact' => ['required', 'array'], 'contact.salutation_id' => ['nullable', 'integer'], 'contact.title' => ['nullable', 'string', 'max:100'], 'contact.first_name' => ['required', 'string', 'max:255'], 'contact.last_name' => ['required', 'string', 'max:255'], 'contact.responsibility' => ['nullable', 'string', 'max:255'], 'contact.phone' => ['nullable', 'string', 'max:100'], 'contact.fax' => ['nullable', 'string', 'max:100'], 'contact.email' => ['nullable', 'email', 'max:255', new PlausibleEmailDomain], ])['contact']; } catch (ValidationException $exception) { return $this->legacyValidationError($exception); } $contact = $company->contacts()->create([ 'portal' => $company->portal?->value, 'salutation_key' => match ((int) ($validated['salutation_id'] ?? 0)) { 1 => 'mr', 2 => 'mrs', default => null, }, 'title' => $validated['title'] ?? null, 'first_name' => $validated['first_name'], 'last_name' => $validated['last_name'], 'responsibility' => $validated['responsibility'] ?? null, 'phone' => $validated['phone'] ?? null, 'fax' => $validated['fax'] ?? null, 'email' => $validated['email'] ?? null, ]); return $this->legacyCreated(url("/service/users/me/companies/{$company->id}/contacts/{$contact->id}")); } }