/** * 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}"); } }
/** * Handle the event. * * @param DeletedPost $event * @return void */ public function handle(DeletedNotice $event) { $path = public_path() . '/images/news'; $noticePath = $path . '/' . $event->notice->permalink; $imageLarge = $event->notice->image_large; $imageMedium = $event->notice->image_medium; $imageThumbnail = $event->notice->image_thumbnail; if (File::exists($noticePath)) { // Delete Images $this->image->delete($noticePath, $imageLarge); $this->image->delete($noticePath, $imageMedium); $this->image->delete($noticePath, $imageThumbnail); // Check if there is files into category directory if ($this->directory->filesEmpty($noticePath)) { // Delete post directory $this->directory->delete($noticePath); } } }
/** * Handle the event. * * @param DeletedPost $event * @return void */ public function handle(DeletedPost $event) { $path = public_path() . '/images/posts'; $postPath = $path . '/' . $event->post->permalink; $imageLarge = $event->post->image; $imageMedium = $event->post->image_medium; $imageThumbnail = $event->post->image_thumbnail; if (File::exists($postPath)) { // Delete Images $this->image->delete($postPath, $imageLarge); $this->image->delete($postPath, $imageMedium); $this->image->delete($postPath, $imageThumbnail); // Check if there is files into category directory // if for some reason can't delete files if ($this->directory->filesEmpty($postPath)) { // Delete post directory $this->directory->delete($postPath); } } }
/** * 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'); }