added optimize setting images

fixed upload file bug
master
A1Gard 3 weeks ago
parent 0f70183154
commit bbc03e859c

@ -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']);
}
}
}

@ -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',
],
[

Loading…
Cancel
Save