/** * Handle the event. * * @param SavedArtist $event */ public function handle(SavedArtist $event) { if ($file = $this->file) { // Set Image Full Size Name $filename = $this->image->setName($file); // Set Image Medium Size Name $filename_medium = $this->image->setName($file, 'medium'); // Set Image Medium Size Name $filename_thumbnail = $this->image->setName($file, 'thumbnail'); // Paths $imagesPath = public_path() . '/images/artists'; $artistPath = $imagesPath . '/' . str_replace(' ', '', $event->artist->permalink); // Make Artist Directory $this->directory->make($artistPath); // Delete images if exists if (File::exists($artistPath)) { // Delete full size image $this->image->delete($artistPath, $event->artist->image); // Delete Image Medium Size $this->image->delete($artistPath, $event->artist->image_medium); // Delete Image Thumbnail Size $this->image->delete($artistPath, $event->artist->image_thumbnail); } // Make and upload full image size to artist path $this->image->make($file, 1024, $artistPath, $filename); // Make and upload full medium image size to artist path $this->image->make($file, 960, $artistPath, $filename_medium); // Make and upload full thumbnail image size to artist path $this->image->make($file, 480, $artistPath, $filename_thumbnail); // Update Artist resource image attributes $event->artist->update(['image' => $filename, 'image_medium' => $filename_medium, 'image_thumbnail' => $filename_thumbnail]); } }
/** * Actualiza un usuario existente en la base de datos. * @param Request $request * @param int $id * @return Response */ public function update(UpdateUserRequest $request, $id, Image $image, Directory $directory) { // Find the user from database $user = User::findOrFail($id); // Set form request except image $form = $request->except('image'); // Check is user is Admin or Registered User if (!$form['admin'] and !$form['registered']) { $form['registered'] = true; } // If password is empty assign it with the database records if (!isset($form['password']) or $form['password'] === '') { $form['password'] = $user->password; } // Update user to database $user->update($form); // Update Image if ($request->hasFile('image')) { // Set user image file $file = $request->file('image'); // Set Image Full Size Name $filename = $image->setName($file); // Set Image Medium Size Name $filename_medium = $image->setName($file, 'medium'); // Set Image Medium Size Name $filename_thumbnail = $image->setName($file, 'thumbnail'); // Paths $imagesPath = public_path() . '/images/users'; $userPath = $imagesPath . '/' . str_replace(' ', '', $user->username); // Make User Directory $directory->make($userPath); // Delete images if exists if (File::exists($userPath)) { // Delete image medium size $image->delete($userPath, $user->image); // Delete image medium size $image->delete($userPath, $user->image_medium); // Delete image thumbnail size $image->delete($userPath, $user->image_thumbnail); } // Make and upload full image size to user path $image->make($file, 600, $userPath, $filename); // Make and upload full medium image size to user path $image->make($file, 300, $userPath, $filename_medium); // Make and upload full thumbnail image size to user path $image->make($file, 150, $userPath, $filename_thumbnail); // Update User image name to database $user->update(['image' => $filename, 'image_medium' => $filename_medium, 'image_thumbnail' => $filename_thumbnail]); } // Set confirmation message session()->flash('message', 'Se Actualizó el Usuario "' . $user->name . '" Satisfactoriamente'); // Redirecto to users list return redirect()->route('admin.users.index'); }