$staticPageModel]); } /** * Send contact form data. * * @param \App\Http\Requests\Fo\ContactFormRequest $request * @return \Illuminate\Http\RedirectResponse */ public function contactSubmit(ContactFormRequest $request): \Illuminate\Http\RedirectResponse { /** @var array $validatedData */ $validatedData = $request->validated(); return DB::transaction(function () use ($validatedData) { try { $joinFilePath = ContactFormType::make($validatedData['type'])->hasFileInput() && !empty($validatedData['joinFile']) ? $this->storeFile($validatedData['joinFile']) : null; $data = new MailContactData( Arr::except($validatedData, ['g-recaptcha-response', 'joinFile', 'locale', 'crmsubject']), $joinFilePath ); if (ContactFormType::make($validatedData['type'])->equals(ContactFormType::complain)) { // Send to Passerelle if it is a complain about a product. \dispatch(new SendPasserelleMail($data, $joinFilePath)); } else if (isset($validatedData['locale']) && ContactFormType::make($validatedData['locale'])->equals(ContactFormType::nl)) { // Send to Export Mailing List if it is a complain from NL page. app()->setLocale('nl'); \dispatch(new SendNLMail($data, $joinFilePath)); } else { // Send to the CRM. if ($joinFilePath) { $relativePath = str_replace(storage_path('app/public') . '/', '', $joinFilePath); $binary = Storage::disk('public')->get($relativePath); $base64 = base64_encode($binary); } /** @var \LDC\LDCCRM\CrmApiV4 */ $crm = app('crmAPI'); $crm->setClaim( $validatedData['lastname'], $validatedData['firstname'], $validatedData['email'], $validatedData['message'], config('crm.brand'), ContactFormType::make($validatedData['type'])->crmId(), $validatedData['address'], $validatedData['town'], $validatedData['postal'], $base64 ?? null, ); // Send mail. \dispatch(new SendClaimMail($data, $joinFilePath)); } return back()->with('success', trans('contact.message_contact_send')); } catch (AbortContactMailer $e) { Log::error('Fail to build mail from complain page ', ['exception' => $e]); } //end try return back()->withInput()->with('error', trans('contact.message_contact_failed')); }); } /** * Store the file sent in the request if it exists. * * @param \Illuminate\Http\UploadedFile|null $file * * @return string|null */ private function storeFile(\Illuminate\Http\UploadedFile|null $file): string|null { $joinFilePath = null; $joinFile = ''; if ($file) { $uniqIdDirectory = \uniqid(); $joinFile = Storage::disk('local')->put( sprintf('public/tmp/%s', $uniqIdDirectory), $file ); $joinFilePath = storage_path('app/' . $joinFile); } return $joinFilePath; } }