public function putUpdate(Request $request)
 {
     if (!ACL::hasPermission('websiteSettings', 'edit')) {
         return redirect(route('home'))->withErrors(['Você não tem permissão para editar os dados do site.']);
     }
     $this->validate($request, ['title' => 'required|max:50', 'costumerServicePhone' => 'required', 'address' => 'required', 'email' => 'required|email|max:50'], ['title.required' => 'Informe o título do site', 'title.max' => 'O título do site não pode ter mais de :max caracteres', 'costumerServicePhone.required' => 'Informe o telefone SAC', 'address.required' => 'Informe o endereço', 'email.required' => 'Informe o e-mail padrão do website', 'email.email' => 'Informe um e-mail válido', 'email.email' => 'O e-mail não pode passar de :max caracteres']);
     $websiteSettings = WebsiteSettings::find($this->websiteSettingsId);
     $websiteSettings->title = $request->title;
     $websiteSettings->costumerServicePhone = $request->costumerServicePhone;
     $websiteSettings->phone = $request->phone;
     $websiteSettings->address = $request->address;
     $websiteSettings->email = $request->email;
     $websiteSettings->facebook = $request->facebook;
     $websiteSettings->twitter = $request->twitter;
     $websiteSettings->youtube = $request->youtube;
     $websiteSettings->instagram = $request->instagram;
     $websiteSettings->linkedin = $request->linkedin;
     $websiteSettings->googleAnalytics = $request->googleAnalytics;
     $websiteSettings->websiteOk = $request->websiteOk;
     if ($request->favicon) {
         //DELETE OLD FAVICON
         if ($request->currentFavicon != "") {
             if (File::exists($this->folder . $request->currentFavicon)) {
                 File::delete($this->folder . $request->currentFavicon);
             }
         }
         $extension = $request->favicon->getClientOriginalExtension();
         $nameFavicon = "favicon." . $extension;
         Image::make($request->file('favicon'))->resize($this->faviconWidth, $this->faviconHeight)->save($this->folder . $nameFavicon);
         $websiteSettings->favicon = $nameFavicon;
     }
     if ($request->avatar) {
         //DELETE OLD AVATAR
         if ($request->currentAvatar != "") {
             if (File::exists($this->folder . $request->currentAvatar)) {
                 File::delete($this->folder . $request->currentAvatar);
             }
         }
         $extension = $request->avatar->getClientOriginalExtension();
         //$nameAvatar = Carbon::now()->format('YmdHis').".".$extension;
         $nameAvatar = "avatar." . $extension;
         $img = Image::make($request->file('avatar'));
         if ($request->avatarCropAreaW > 0 or $request->avatarCropAreaH > 0 or $request->avatarPositionX or $request->avatarPositionY) {
             $img->crop($request->avatarCropAreaW, $request->avatarCropAreaH, $request->avatarPositionX, $request->avatarPositionY);
         }
         $img->resize($this->avatarWidth, $this->avatarHeight)->save($this->folder . $nameAvatar);
         $websiteSettings->avatar = $nameAvatar;
     }
     if ($request->appleTouchIcon) {
         //DELETE OLD APPLE TOUCH ICON
         if ($request->currentAppleTouchIcon != "") {
             if (File::exists($this->folder . $request->currentAppleTouchIcon)) {
                 File::delete($this->folder . $request->currentAppleTouchIcon);
             }
         }
         $extension = $request->appleTouchIcon->getClientOriginalExtension();
         $nameAppleTouchIcon = "apple-touch-icon." . $extension;
         Image::make($request->file('appleTouchIcon'))->resize($this->appleTouchIconWidth, $this->appleTouchIconHeight)->save($this->folder . $nameAppleTouchIcon);
         $websiteSettings->appleTouchIcon = $nameAppleTouchIcon;
     }
     //WRITE JSON
     Handler::writeFile("websiteSettings.json", json_encode($websiteSettings));
     $websiteSettings->save();
     $success = "Dados do site editados com sucesso!";
     return redirect(route('websiteSettings'))->with(compact('success'));
 }
 public function putUpdate(Request $request, $folder = "assets/images/_upload/websiteSettings/")
 {
     if (!ACL::hasPermission('websiteSettings', 'edit')) {
         return redirect(route('home'))->withErrors(['You don\'t have permission for edit the website settings.']);
     }
     $this->validate($request, ['title' => 'required|max:50', 'description' => 'required|max:200', 'email' => 'required|email|max:50', 'keywords' => 'required']);
     $websiteSettings = WebsiteSettings::find($this->websiteSettingsId);
     $websiteSettings->title = $request->title;
     $websiteSettings->description = $request->description;
     $websiteSettings->keywords = $request->keywords;
     $websiteSettings->phone = $request->phone;
     $websiteSettings->email = $request->email;
     $websiteSettings->city = $request->city;
     $websiteSettings->state = $request->state;
     $websiteSettings->country = $request->country;
     $websiteSettings->github = $request->github;
     $websiteSettings->linkedin = $request->linkedin;
     if ($request->logotype) {
         //DELETE OLD LOGOTYPE
         if ($request->currentLogotype != "") {
             if (File::exists($folder . $request->currentLogotype)) {
                 File::delete($folder . $request->currentLogotype);
             }
         }
         $extension = $request->logotype->getClientOriginalExtension();
         $nameLogotype = "logo-brunomartins." . $extension;
         Image::make($request->file('logotype'))->resize($this->logotypeWidth, $this->logotypeHeight)->save($folder . $nameLogotype);
         $websiteSettings->logotype = $nameLogotype;
     }
     if ($request->favicon) {
         //DELETE OLD FAVICON
         if ($request->currentFavicon != "") {
             if (File::exists($folder . $request->currentFavicon)) {
                 File::delete($folder . $request->currentFavicon);
             }
         }
         $extension = $request->favicon->getClientOriginalExtension();
         $nameFavicon = "favicon." . $extension;
         Image::make($request->file('favicon'))->resize($this->faviconWidth, $this->faviconHeight)->save($folder . $nameFavicon);
         $websiteSettings->favicon = $nameFavicon;
     }
     if ($request->avatar) {
         //DELETE OLD AVATAR
         if ($request->currentAvatar != "") {
             if (File::exists($folder . $request->currentAvatar)) {
                 File::delete($folder . $request->currentAvatar);
             }
         }
         $extension = $request->avatar->getClientOriginalExtension();
         //$nameAvatar = Carbon::now()->format('YmdHis').".".$extension;
         $nameAvatar = "avatar." . $extension;
         $img = Image::make($request->file('avatar'));
         if ($request->avatarCropAreaW > 0 or $request->avatarCropAreaH > 0 or $request->avatarPositionX or $request->avatarPositionY) {
             $img->crop($request->avatarCropAreaW, $request->avatarCropAreaH, $request->avatarPositionX, $request->avatarPositionY);
         }
         $img->resize($this->avatarWidth, $this->avatarHeight)->save($folder . $nameAvatar);
         $websiteSettings->avatar = $nameAvatar;
     }
     if ($request->appleTouchIcon) {
         //DELETE OLD APPLE TOUCH ICON
         if ($request->currentAppleTouchIcon != "") {
             if (File::exists($folder . $request->currentAppleTouchIcon)) {
                 File::delete($folder . $request->currentAppleTouchIcon);
             }
         }
         $extension = $request->appleTouchIcon->getClientOriginalExtension();
         $nameAppleTouchIcon = "apple-touch-icon." . $extension;
         Image::make($request->file('appleTouchIcon'))->resize($this->appleTouchIconWidth, $this->appleTouchIconHeight)->save($folder . $nameAppleTouchIcon);
         $websiteSettings->appleTouchIcon = $nameAppleTouchIcon;
     }
     //WRITE JSON
     Handler::writeFile("websiteSettings.json", json_encode($websiteSettings));
     $websiteSettings->save();
     $success = "Website settings edited successfully.";
     return redirect(route('websiteSettings'))->with(compact('success'));
 }
 public function putUpdate(Request $request)
 {
     if (!ACL::hasPermission('websiteSettings', 'edit')) {
         return redirect(route('home'))->withErrors(['Você não tem permissão para editar os dados do site.']);
     }
     $this->validate($request, ['title' => 'required|max:50', 'email' => 'required|email|max:50', 'certificate' => 'required', 'callText' => 'required', 'buttonText' => 'required', 'buttonUrl' => 'required'], ['title.required' => 'Informe o título do site', 'title.max' => 'O título do site não pode ter mais de :max caracteres', 'certificate.required' => 'Informe o certificado da CAIXA', 'callText.required' => 'Informe o texto da chamada para a home', 'buttonText.required' => 'Informe o texto do botão', 'buttonUrl.required' => 'Informe a URL do botão']);
     $websiteSettings = WebsiteSettings::find($this->websiteSettingsId);
     $websiteSettings->title = $request->title;
     $websiteSettings->email = $request->email;
     $websiteSettings->certificate = $request->certificate;
     $websiteSettings->callText = $request->callText;
     $websiteSettings->buttonText = $request->buttonText;
     $websiteSettings->buttonUrl = $request->buttonUrl;
     $websiteSettings->facebook = $request->facebook;
     $websiteSettings->instagram = $request->instagram;
     $websiteSettings->twitter = $request->twitter;
     $websiteSettings->youtube = $request->youtube;
     $websiteSettings->googleAnalytics = $request->googleAnalytics;
     $websiteSettings->websiteOk = $request->websiteOk;
     $websiteSettings->registerOk = $request->registerOk;
     $websiteSettings->votingOk = $request->votingOk;
     $websiteSettings->winnersOk = $request->winnersOk;
     if ($request->favicon) {
         //DELETE OLD FAVICON
         if ($request->currentFavicon != "") {
             if (File::exists($this->folder . $request->currentFavicon)) {
                 File::delete($this->folder . $request->currentFavicon);
             }
         }
         $extension = $request->favicon->getClientOriginalExtension();
         $nameFavicon = "favicon." . $extension;
         Image::make($request->file('favicon'))->resize($this->faviconWidth, $this->faviconHeight)->save($this->folder . $nameFavicon);
         $websiteSettings->favicon = $nameFavicon;
     }
     if ($request->avatar) {
         //DELETE OLD AVATAR
         if ($request->currentAvatar != "") {
             if (File::exists($this->folder . $request->currentAvatar)) {
                 File::delete($this->folder . $request->currentAvatar);
             }
         }
         $extension = $request->avatar->getClientOriginalExtension();
         //$nameAvatar = Carbon::now()->format('YmdHis').".".$extension;
         $nameAvatar = "avatar." . $extension;
         $img = Image::make($request->file('avatar'));
         if ($request->avatarCropAreaW > 0 or $request->avatarCropAreaH > 0 or $request->avatarPositionX or $request->avatarPositionY) {
             $img->crop($request->avatarCropAreaW, $request->avatarCropAreaH, $request->avatarPositionX, $request->avatarPositionY);
         }
         $img->resize($this->avatarWidth, $this->avatarHeight)->save($this->folder . $nameAvatar);
         $websiteSettings->avatar = $nameAvatar;
     }
     if ($request->appleTouchIcon) {
         //DELETE OLD APPLE TOUCH ICON
         if ($request->currentAppleTouchIcon != "") {
             if (File::exists($this->folder . $request->currentAppleTouchIcon)) {
                 File::delete($this->folder . $request->currentAppleTouchIcon);
             }
         }
         $extension = $request->appleTouchIcon->getClientOriginalExtension();
         $nameAppleTouchIcon = "apple-touch-icon." . $extension;
         Image::make($request->file('appleTouchIcon'))->resize($this->appleTouchIconWidth, $this->appleTouchIconHeight)->save($this->folder . $nameAppleTouchIcon);
         $websiteSettings->appleTouchIcon = $nameAppleTouchIcon;
     }
     //WRITE JSON
     Handler::writeFile("websiteSettings.json", json_encode($websiteSettings));
     $websiteSettings->save();
     $success = "Dados do site editados com sucesso!";
     return redirect(route('websiteSettings'))->with(compact('success'));
 }