This commit is contained in:
2026-04-16 11:25:40 +05:00
parent 2ba5677c45
commit 3aa4601229
13 changed files with 80 additions and 234 deletions

View File

@@ -43,20 +43,8 @@ class Update extends FormRequest
public function getImage(Category $category): string
{
if ($this->hasFile('image')) {
if (env('FILESYSTEM_DISK') == 's3') {
// delete old image from s3
Storage::disk('s3')->delete($category->image);
$folder = "uploads/categories";
return (string) $this->file('image')->store($folder);
} else {
// detele old image
if (is_file($category->image)) {
unlink($category->image);
}
return $this->file('image')->store('uploads/categories', 'local');
}
Storage::delete($category->image);
return (string) $this->file('image')->store('uploads/categories');
} else {
return 'null';
}

View File

@@ -63,15 +63,7 @@ class Update extends FormRequest
public function getPoster(Product $product): string
{
if ($this->hasFile('poster')) {
if (env('FILESYSTEM_DISK') == 's3') {
// delete old file from s3
Storage::disk('s3')->delete($product->poster);
} else {
// delete old file
$oldPath = public_path($product->poster);
if (is_file($oldPath)) unlink($oldPath);
}
Storage::delete($product->poster);
$folder = "uploads/posters/" . Carbon::now()->format('Y/m/d');
return (string) $this->file('poster')->store($folder);
}
@@ -85,13 +77,9 @@ class Update extends FormRequest
public function getCalc(Product $product): string|null
{
if ($this->hasFile('calc')) {
if (env('FILESYSTEM_DISK') == 's3' and $product->calc) {
// delete old file from s3
Storage::disk('s3')->delete($product->calc);
} elseif($product->calc) {
unlink($product->calc);
if ($product->calc) {
Storage::delete($product->calc);
}
$folder = "uploads/calc/" . Carbon::now()->format('Y/m/d');
return (string) $this->file('calc')->store($folder);
}
@@ -101,11 +89,9 @@ class Update extends FormRequest
public function getDataSheet(Product $product)
{
if ($this->hasFile('data_sheet')) {
if (is_file($this->get('data_sheet'))) {
unlink($this->get("data_sheet"));
if ($product->data_sheet) {
Storage::delete($product->data_sheet);
}
$folder = "uploads/datasheet/" . Carbon::now()->format('Y/m/d');
return (string) $this->file('data_sheet')->store($folder);
}
@@ -119,18 +105,8 @@ class Update extends FormRequest
public function getPosterThumb(Product $product): string
{
if ($this->hasFile('poster')) {
if (env('FILESYSTEM_DISK') == 's3') {
// delete old file from s3
Storage::disk('s3')->delete($product->poster_thumb);
} else {
// delete old file local
$oldPath = public_path($product->poster_thumb);
if (is_file($oldPath)) unlink($oldPath);
}
$image = $this->file('poster');
$tempPath = $image->store('temp', 'public');
Storage::delete($product->poster_thumb);
$tempPath = $this->file('poster')->store('temp', 'public');
$resizer = new ImageResize();
return $resizer->resize($tempPath, 322, 'posters', true);
}