App\Http\Controllers\AccountController::updateDetails PHP Method

updateDetails() public method

public updateDetails ( UpdateAccountRequest $request ) : Illuminate\Http\RedirectResponse
$request App\Http\Requests\UpdateAccountRequest
return Illuminate\Http\RedirectResponse
    public function updateDetails(UpdateAccountRequest $request)
    {
        $account = Auth::user()->account;
        $this->accountRepo->save($request->input(), $account);
        /* Logo image file */
        if ($uploaded = Input::file('logo')) {
            $path = Input::file('logo')->getRealPath();
            $disk = $account->getLogoDisk();
            if ($account->hasLogo() && !Utils::isNinjaProd()) {
                $disk->delete($account->logo);
            }
            $extension = strtolower($uploaded->getClientOriginalExtension());
            if (empty(Document::$types[$extension]) && !empty(Document::$extraExtensions[$extension])) {
                $documentType = Document::$extraExtensions[$extension];
            } else {
                $documentType = $extension;
            }
            if (!in_array($documentType, ['jpeg', 'png', 'gif'])) {
                Session::flash('warning', 'Unsupported file type');
            } else {
                $documentTypeData = Document::$types[$documentType];
                $filePath = $uploaded->path();
                $size = filesize($filePath);
                if ($size / 1000 > MAX_DOCUMENT_SIZE) {
                    Session::flash('warning', 'File too large');
                } else {
                    if ($documentType != 'gif') {
                        $account->logo = $account->account_key . '.' . $documentType;
                        $imageSize = getimagesize($filePath);
                        $account->logo_width = $imageSize[0];
                        $account->logo_height = $imageSize[1];
                        $account->logo_size = $size;
                        // make sure image isn't interlaced
                        if (extension_loaded('fileinfo')) {
                            $image = Image::make($path);
                            $image->interlace(false);
                            $imageStr = (string) $image->encode($documentType);
                            $disk->put($account->logo, $imageStr);
                            $account->logo_size = strlen($imageStr);
                        } else {
                            $stream = fopen($filePath, 'r');
                            $disk->getDriver()->putStream($account->logo, $stream, ['mimetype' => $documentTypeData['mime']]);
                            fclose($stream);
                        }
                    } else {
                        if (extension_loaded('fileinfo')) {
                            $image = Image::make($path);
                            $image->resize(200, 120, function ($constraint) {
                                $constraint->aspectRatio();
                            });
                            $account->logo = $account->account_key . '.png';
                            $image = Image::canvas($image->width(), $image->height(), '#FFFFFF')->insert($image);
                            $imageStr = (string) $image->encode('png');
                            $disk->put($account->logo, $imageStr);
                            $account->logo_size = strlen($imageStr);
                            $account->logo_width = $image->width();
                            $account->logo_height = $image->height();
                        } else {
                            Session::flash('warning', 'Warning: To support gifs the fileinfo PHP extension needs to be enabled.');
                        }
                    }
                }
            }
            $account->save();
        }
        event(new UserSettingsChanged());
        Session::flash('message', trans('texts.updated_settings'));
        return Redirect::to('settings/' . ACCOUNT_COMPANY_DETAILS);
    }