Skip to content
This repository has been archived by the owner on Jul 9, 2023. It is now read-only.

Commit

Permalink
solved delete image type
Browse files Browse the repository at this point in the history
  • Loading branch information
AliGhaleyan committed Mar 5, 2020
1 parent 79feba6 commit 2813279
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
12 changes: 8 additions & 4 deletions src/BaseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function getFile($name = null)

return File::query()
->where("name", $name)
->firstOrFail();
->first();
}


Expand All @@ -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;
}


Expand Down
23 changes: 20 additions & 3 deletions src/Types/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
class Image extends BaseType
{
protected $sizes = null;

protected $thumb = null;


Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -136,6 +152,7 @@ public function getSizes()
return $this->sizes;
}


/**
* set sizes
*
Expand All @@ -158,4 +175,4 @@ public function getThumbSize()
{
return $this->thumb;
}
}
}

0 comments on commit 2813279

Please sign in to comment.