/**
  * 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]);
     }
 }
 /**
  * Handle the event.
  *
  * @param  DeletedArtistEvent  $event
  * @return void
  */
 public function handle(DeletedArtist $event)
 {
     $path = public_path() . '/images/artists';
     $directory = $event->artist->permalink;
     $image_full = $event->artist->image;
     $image_medium = $event->artist->image_medium;
     $image_thumbnail = $event->artist->image_thumbnail;
     if (File::exists("{$path}/{$directory}")) {
         // Delete Images
         $this->image->delete($path, $directory . '/' . $image_full);
         $this->image->delete($path, $directory . '/' . $image_medium);
         $this->image->delete($path, $directory . '/' . $image_thumbnail);
         // Delete directory
         $this->directory->delete("{$path}/{$directory}");
     }
 }
Example #3
0
 /**
  * Handle the event.
  *
  * @param  SavedPost $event
  */
 public function handle(SavedPost $event)
 {
     if ($this->request->hasFile('image')) {
         // Set file to file variable
         $file = $this->request->file('image');
         // Set Image Full Size Name
         $filename = $this->image->setName($file, 'large');
         // 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/posts';
         $postPath = $imagesPath . '/' . $event->post->permalink;
         // Create Post Directory
         File::exists($postPath) or File::makeDirectory($postPath);
         // Delete images if exists
         if (File::exists($postPath)) {
             // Delete full size image
             $this->image->delete($postPath, $event->post->image);
             // Delete Image Medium Size
             $this->image->delete($postPath, $event->post->image_medium);
             // Delete Image Thumbnail Size
             $this->image->delete($postPath, $event->post->image_thumbnail);
         }
         // Create image full size if not exists
         if (!File::exists($postPath . '/' . $filename)) {
             // Make the full size image and upload to final destination
             $this->image->make($file, 1024, $postPath, $filename);
         }
         // Create image medium size if not exists
         if (!File::exists($postPath . '/' . $filename_medium)) {
             // Crop the full size image and upload to final destination
             $this->image->make($file, 800, $postPath, $filename_medium);
         }
         // Create image thumbnail size if not exists
         if (!File::exists($postPath . '/' . $filename_thumbnail)) {
             // Make and upload full thumbnail image size to artist path
             $this->image->make($file, 400, $postPath, $filename_thumbnail);
         }
         // Update Artist resource image attributes
         $event->post->update(['image' => $filename, 'image_medium' => $filename_medium, 'image_thumbnail' => $filename_thumbnail]);
     }
 }
Example #4
0
 /**
  * Elimina un usuario de la base de datos.
  *
  * @param  int $id
  * @return Response
  */
 public function destroy($id, Image $image, Directory $directory)
 {
     $user = User::findOrFail($id);
     // Paths
     $imagesPath = public_path() . '/images/users';
     $userPath = $imagesPath . '/' . str_replace(' ', '', $user->username);
     // Delete images if exists
     if (File::exists($userPath)) {
         // Delete image full 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);
         $directory->delete($userPath);
     }
     $user->delete();
     session()->flash('message', 'Se Eliminó el Usuario "' . $user->name . '" Satisfactoriamente');
     return redirect()->route('admin.users.index');
 }