From bbc03e859cb46fd3dfd88be3d3e05930a1181014 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Thu, 5 Dec 2024 02:23:55 +0330 Subject: [PATCH] added optimize setting images fixed upload file bug --- app/Http/Controllers/Admin/SettingController.php | 16 +++++++++++++++- database/seeders/SettingSeeder.php | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Admin/SettingController.php b/app/Http/Controllers/Admin/SettingController.php index 1fdb4e0..44799e2 100644 --- a/app/Http/Controllers/Admin/SettingController.php +++ b/app/Http/Controllers/Admin/SettingController.php @@ -10,6 +10,7 @@ use App\Models\Menu; use App\Models\Setting; use Illuminate\Http\Request; use Illuminate\Support\Facades\Artisan; +use Spatie\Image\Image; class SettingController extends Controller { @@ -91,11 +92,24 @@ class SettingController extends Controller } $files = $request->allFiles(); if (isset($files['file'])) { + $format = getSetting('optimize'); foreach ($files['file'] as $index => $file) { + if ( ($file->guessExtension() == 'jpg' || $file->guessExtension() == 'png') && ($index != 'site_image') ) { + + $i = Image::load($file->getRealPath()) + ->optimize() + ->format($format); + + $file->move(public_path('upload/images/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); + $optimizedFile = public_path('upload/images/optimized-'). str_replace('_','.',$index); + $optimizedFile = str_replace(['jpg','png','gif'],'webp',$optimizedFile); + $i->save($optimizedFile); + }else if ($file->guessExtension() == 'mp4' || $file->guessExtension() == 'mp3'){ $file->move(public_path('upload/media/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); }else{ - $file->move(public_path('upload/images/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); + + $file->move(public_path('upload/file/'), str_replace('_','.',$index) );//store('/images/'.,['disk' => 'public']); } } } diff --git a/database/seeders/SettingSeeder.php b/database/seeders/SettingSeeder.php index 52e6f9d..236bb08 100644 --- a/database/seeders/SettingSeeder.php +++ b/database/seeders/SettingSeeder.php @@ -201,14 +201,14 @@ class SettingSeeder extends Seeder 'title' => __('Product image size'), 'key' => 'product_thumb', 'type' => 'TEXT', - 'value' => '500x500', + 'value' => '900x900', 'size' => '6', ], [ 'title' => __('Post thumbnail size'), 'key' => 'post_thumb', 'type' => 'TEXT', - 'value' => '500x500', + 'value' => '900x900', 'size' => '6', ], [