diff --git a/src/BaseType.php b/src/BaseType.php index 86de1c6..ebddd27 100644 --- a/src/BaseType.php +++ b/src/BaseType.php @@ -218,7 +218,7 @@ public function getFile($name = null) return File::query() ->where("name", $name) - ->firstOrFail(); + ->first(); } @@ -239,9 +239,13 @@ public function delete($filename = null) { /** @var File $file */ $file = $this->getFile($filename); - $flag = $this->handleDelete($file); - $file->delete(); - return $flag; + + if ($file) { + $flag = $this->handleDelete($file); + $file->delete(); + } + + return $flag ?? true; } diff --git a/src/Types/Image.php b/src/Types/Image.php index a4eb2fa..9efe1d2 100644 --- a/src/Types/Image.php +++ b/src/Types/Image.php @@ -12,6 +12,7 @@ class Image extends BaseType { protected $sizes = null; + protected $thumb = null; @@ -62,8 +63,23 @@ protected function handleDelete(File $file) FileFacade::delete($sizePath); } - FileFacade::delete($file->base_path . "thumb/" . $file->file_name); - FileFacade::delete($file->base_path . "original/" . $file->file_name); + $thumbSize = $file->base_path . "thumb/" . $file->file_name; + $originalSize = $file->base_path . "original/" . $file->file_name; + + if ($file->private) { + $thumbSize = storage_path($thumbSize); + } else { + $thumbSize = public_path($thumbSize); + } + + if ($file->private) { + $originalSize = storage_path($originalSize); + } else { + $originalSize = public_path($originalSize); + } + + FileFacade::delete($thumbSize); + FileFacade::delete($originalSize); return true; } @@ -136,6 +152,7 @@ public function getSizes() return $this->sizes; } + /** * set sizes * @@ -158,4 +175,4 @@ public function getThumbSize() { return $this->thumb; } -} \ No newline at end of file +}