public function update(UpdateAccountRequest $request) { $account = Auth::user()->account; $this->accountRepo->save($request->input(), $account); $transformer = new AccountTransformer(null, $request->serializer); $account = $this->createItem($account, $transformer, 'account'); return $this->response($account); }
public function updateAccount(UpdateAccountRequest $request, AppMailer $mailer) { $input = $request->all(); $user = \Auth::user(); $user->name = $input['name']; $user->password = $input['password']; $user->save(); session()->flash("message", "Account Updated. Go ahead and create Reports!"); $mailer->sendAccountUpdatedNotification($user); return redirect("/dashboard"); }
/** * @param UpdateAccountRequest $request * @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()) { $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); }
public function update(UpdateAccountRequest $request) { //dataRequest $dataRequest = $request->all(); //check upload Image if (!is_null(Input::file('image'))) { $upload = new UploadImage(); //get old avt $oldAvatar = User::where('id', Input::get('id'))->first(); $image = Input::file('image'); if ($upload->_upload($oldAvatar->avatar, $image)) { } else { return redirect_errors('Error upload image!'); } $user = User::find(Input::get('id')); $user = autoAssignDataToProperty($user, $dataRequest); $user->updated_at = Carbon::now(); //check update if ($user->save()) { return redirect()->back()->with('success', "Update Success!"); } else { return redirect_errors('Error cannot update!'); } } else { //get old Avt $oldAvatar = User::where('id', Input::get('id'))->first(); //check has image if ($oldAvatar->avatar != $this::DEFAULT_IMAGE_PERSON) { //delete old image File::delete($oldAvatar->avatar); } $user = User::find(Input::get('id')); //check update $user = autoAssignDataToProperty($user, $dataRequest); $user->updated_at = Carbon::now(); if ($user->save()) { return redirect()->back()->with('success', "Update Success!"); } else { return redirect_errors('Error cannot update!'); } } //end check update }
public function updateDetails(UpdateAccountRequest $request) { $account = Auth::user()->account; $this->accountRepo->save($request->input(), $account); /* Logo image file */ if ($file = Input::file('logo')) { $path = Input::file('logo')->getRealPath(); File::delete('logo/' . $account->account_key . '.jpg'); File::delete('logo/' . $account->account_key . '.png'); $mimeType = $file->getMimeType(); if ($mimeType == 'image/jpeg') { $path = 'logo/' . $account->account_key . '.jpg'; $file->move('logo/', $account->account_key . '.jpg'); } elseif ($mimeType == 'image/png') { $path = 'logo/' . $account->account_key . '.png'; $file->move('logo/', $account->account_key . '.png'); } else { if (extension_loaded('fileinfo')) { $image = Image::make($path); $image->resize(200, 120, function ($constraint) { $constraint->aspectRatio(); }); $path = 'logo/' . $account->account_key . '.jpg'; Image::canvas($image->width(), $image->height(), '#FFFFFF')->insert($image)->save($path); } else { Session::flash('warning', 'Warning: To support gifs the fileinfo PHP extension needs to be enabled.'); } } // make sure image isn't interlaced if (extension_loaded('fileinfo')) { $img = Image::make($path); $img->interlace(false); $img->save(); } } event(new UserSettingsChanged()); Session::flash('message', trans('texts.updated_settings')); return Redirect::to('settings/' . ACCOUNT_COMPANY_DETAILS); }