user(); /** @var \LDC\LDCCRM\Models\Customer $crmCustomer */ $crmCustomer = $customer->api_data; return view('fo.pages.klub.profile', compact('crmCustomer')); } /** * Update Customer profile * * @param \App\Http\Requests\Fo\Customers\UpdateAccountRequest $request * @return \Illuminate\Http\RedirectResponse */ public function profileUpdate(UpdateAccountRequest $request): RedirectResponse { /** @var \App\Models\Customer $customer */ $customer = auth('frontend')->user(); return $this->updateCrmCustomerInfo($customer, $request->validated()) ? back()->with('success', trans('Vos informations ont bien été enregistrées.')) : back()->withInput()->withErrors(trans('Une erreur est survenue, merci de réessayer ultérieurement.')); } /** * Show update customer password form * * @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory */ public function password() { return view('fo.auth.passwords.change'); } /** * Update customer password * * @param \App\Http\Requests\Fo\Customers\UpdatePasswordRequest $request * @return \Illuminate\Http\RedirectResponse */ public function passwordSubmit(UpdatePasswordRequest $request): RedirectResponse { /** @var \App\Models\Customer */ $customer = \auth('frontend')->user(); if ($this->updateCrmCustomerInfo($customer, ['password' => $request->input('password')])) { event(new PasswordReset($customer)); return back()->with('success', trans('Vos informations ont bien été enregistrées.')); } return back()->withInput()->withErrors(trans('Une erreur est survenue, merci de réessayer ultérieurement.')); } /** * Updates user info * * @param \App\Models\Customer $customer * @param array $data * @return boolean * @throws \Illuminate\Validation\ValidationException If something failed. */ private function updateCrmCustomerInfo(Customer $customer, array $data) { return DB::transaction(function () use ($customer, $data) { try { if (\array_key_exists('email', $data)) { $customer->email = $data['email']; $customer->saveOrFail(); } return $customer->updateApiData($data); } catch (CrmValidationException $e) { throw ValidationException::withMessages([ 'error' => $e->getMessage() ]); } catch (ApiErrorException $e) { if ($e->getApiError()->equals(ApiError::validationFailed)) { throw ValidationException::withMessages([ 'error' => $e->getMessage() ]); } report($e); return false; } //end try }); } }