added optimize for category group slider

fixed bug part seeder
added watermark2 to SettingSeeder
added upload gitignore
pull/44/head
A1Gard 6 months ago
parent 3be0a8c4e8
commit 7467fbd7fe

@ -9,6 +9,10 @@ use App\Models\Access;
use App\Models\Category;
use Illuminate\Http\Request;
use App\Helper;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Fit;
use Spatie\Image\Enums\Unit;
use Spatie\Image\Image;
use function App\Helpers\hasCreateRoute;
class CategoryController extends XController
@ -17,10 +21,10 @@ class CategoryController extends XController
// protected $_MODEL_ = Category::class;
// protected $SAVE_REQUEST = CategorySaveRequest::class;
protected $cols = ['name','subtitle','parent_id'];
protected $extra_cols = ['id','slug','image'];
protected $cols = ['name', 'subtitle', 'parent_id'];
protected $extra_cols = ['id', 'slug', 'image'];
protected $searchable = ['name','subtitle','description'];
protected $searchable = ['name', 'subtitle', 'description'];
protected $listView = 'admin.categories.category-list';
@ -55,11 +59,33 @@ class CategoryController extends XController
$category->description = $request->input('description');
$category->parent_id = $request->input('parent_id');
$category->slug = $this->getSlug($category);
if ($request->has('image')){
$category->image = $this->storeFile('image',$category, 'categories');
if ($request->has('image')) {
$category->image = $this->storeFile('image', $category, 'categories');
$key = 'image';
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($request->file($key)->extension());
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
15, Unit::Percent, 15, Unit::Percent, Fit::Contain, 50);
}
$i->save(storage_path() . '/app/public/categories/optimized-'. $category->$key);
}
if ($request->has('bg')){
$category->bg = $this->storeFile('bg',$category, 'categories');
if ($request->has('bg')) {
$category->bg = $this->storeFile('bg', $category, 'categories');
$key = 'bg';
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($request->file($key)->extension());
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
15, Unit::Percent, 15, Unit::Percent, Fit::Contain, 50);
}
$i->save(storage_path() . '/app/public/categories/optimized-'. $category->$key);
}
$category->save();
return $category;
@ -74,7 +100,7 @@ class CategoryController extends XController
{
//
$cats = Category::all();
return view($this->formView,compact('cats'));
return view($this->formView, compact('cats'));
}
/**
@ -84,7 +110,7 @@ class CategoryController extends XController
{
//
$cats = Category::all();
return view($this->formView, compact('item','cats'));
return view($this->formView, compact('item', 'cats'));
}
public function bulk(Request $request)
@ -134,22 +160,24 @@ class CategoryController extends XController
/**sort*/
public function sort(){
public function sort()
{
$items = Category::orderBy('sort')
->get(['id','name','parent_id']);
return view('admin.commons.sort',compact('items'));
->get(['id', 'name', 'parent_id']);
return view('admin.commons.sort', compact('items'));
}
public function sortSave(Request $request){
public function sortSave(Request $request)
{
// return $request->items;
foreach ($request->items as $key => $item){
foreach ($request->items as $key => $item) {
$i = Category::whereId($item['id'])->first();
$i->sort = $key;
$i->parent_id = $item['parentId']??null;
$i->parent_id = $item['parentId'] ?? null;
$i->save();
}
logAdmin(__METHOD__,__CLASS__,null);
return ['OK' => true,'message' => __("As you wished sort saved")];
logAdmin(__METHOD__, __CLASS__, null);
return ['OK' => true, 'message' => __("As you wished sort saved")];
}
/*sort**/

@ -9,6 +9,10 @@ use App\Models\Access;
use App\Models\Group;
use Illuminate\Http\Request;
use App\Helper;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Fit;
use Spatie\Image\Enums\Unit;
use Spatie\Image\Image;
use function App\Helpers\hasCreateRoute;
class GroupController extends XController
@ -56,9 +60,31 @@ class GroupController extends XController
$group->slug = $this->getSlug($group);
if ($request->has('image')){
$group->image = $this->storeFile('image',$group, 'groups');
$key = 'image';
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($request->file($key)->extension());
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
15, Unit::Percent, 15, Unit::Percent, Fit::Contain, 50);
}
$i->save(storage_path() . '/app/public/groups/optimized-'. $group->$key);
}
if ($request->has('bg')){
$group->bg = $this->storeFile('bg',$group, 'groups');
$key = 'bg';
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($request->file($key)->extension());
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
15, Unit::Percent, 15, Unit::Percent, Fit::Contain, 50);
}
$i->save(storage_path() . '/app/public/groups/optimized-'. $group->$key);
}
$group->save();
return $group;

@ -9,6 +9,10 @@ use App\Models\Access;
use App\Models\Slider;
use Illuminate\Http\Request;
use App\Helper;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Fit;
use Spatie\Image\Enums\Unit;
use Spatie\Image\Image;
use function App\Helpers\hasCreateRoute;
class SliderController extends XController
@ -57,11 +61,20 @@ class SliderController extends XController
$name = time() . '.' . request()->cover->getClientOriginalExtension();
$slider->image = $name;
$request->file('cover')->storeAs('public/sliders', $name);
}
if ($request->has('cover')){
$slider->image = $this->storeFile('cover',$slider, 'sliders');
$key = 'cover';
$i = Image::load($request->file($key)->getPathname())
->optimize()
// ->nonQueued()
->format($request->file($key)->extension());
if (getSetting('watermark2')) {
$i->watermark(public_path('upload/images/logo.png'),
AlignPosition::BottomLeft, 5, 5, Unit::Percent,
15, Unit::Percent, 15, Unit::Percent, Fit::Contain, 50);
}
$i->save(storage_path() . '/app/public/sliders/optimized-'. $slider->image);
}
$slider->save();
return $slider;

@ -19,6 +19,14 @@ class Category extends Model
return asset('/assets/upload/logo.svg');
}
return \Storage::url('categories/optimized-' . $this->image);
}
public function imgOriginalUrl()
{
if ($this->image == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('categories/' . $this->image);
}
@ -28,6 +36,14 @@ class Category extends Model
return asset('/assets/upload/logo.svg');
}
return \Storage::url('categories/optimized-' . $this->bg);
}
public function bgOriginalUrl()
{
if ($this->bg == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('categories/' . $this->bg);
}

@ -38,12 +38,21 @@ class Group extends Model
return $this->belongsTo(\App\Models\User::class);
}
public function imgUrl()
{
if ($this->image == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('groups/optimized-' . $this->image);
}
public function imgOriginalUrl()
{
if ($this->image == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('groups/' . $this->image);
}
@ -53,9 +62,16 @@ class Group extends Model
return asset('/assets/upload/logo.svg');
}
return \Storage::url('groups/' . $this->bg);
return \Storage::url('groups/optimized-' . $this->bg);
}
public function bgOriginalUrl()
{
if ($this->bg == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('groups/' . $this->bg);
}
public function attachs(){
return $this->morphMany(Attachment::class,'attachable');
}

@ -18,7 +18,15 @@ class Slider extends Model
public function imgUrl()
{
if ($this->image == null) {
return null;
return asset('/assets/upload/logo.svg');
}
return \Storage::url('sliders/optimized-' . $this->image);
}
public function imgOriginalUrl()
{
if ($this->image == null) {
return asset('/assets/upload/logo.svg');
}
return \Storage::url('sliders/' . $this->image);

@ -14,7 +14,6 @@ return new class extends Migration
Schema::create('parts', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('area_id');
$table->integer('sort')->default(0);
$table->string('segment');
$table->string('part');
$table->json('data')->default('[]');

@ -18,7 +18,7 @@ class PartSeeder extends Seeder
$part = new Part();
$part->segment = 'preloader';
$part->part = 'PreloaderImage';
$part->part = 'PreloaderCircle';
$part->area_id = Area::where('name','preloader')->first()->id;
$part->save();

@ -135,14 +135,21 @@ class SettingSeeder extends Seeder
'key' => 'optimize',
'type' => 'TEXT',
'value' => 'webp',
'size' => '6',
'size' => '4',
],
[
'title' => __('Watermark'),
'title' => __('Watermark (product, gallery, post) '),
'key' => 'watermark',
'type' => 'CHECKBOX',
'value' => false,
'size' => '6',
'size' => '4',
],
[
'title' => __('Watermark ( category, slider, group)'),
'key' => 'watermark2',
'type' => 'CHECKBOX',
'value' => false,
'size' => '4',
],
[
'title' => __('Product thumbnail size'),

@ -0,0 +1 @@
./*

@ -2,7 +2,4 @@
// IF YOU WANT ADD ANY CODE CREATE NEW JS INTO client-custom
import "./client-custom/assetsNode.js";
import "./client-custom/confirm.js";
import "../views/segments/preloader/PreloaderCircle/PreloaderCircle.js";
import "../views/segments/top/TopSimple/TopSimple.js";
import "../views/segments/slider/SliderSimple/SliderSimple.js";
import "../views/segments/top/TopSimple/TopSimple.js";
import "../views/segments/preloader/PreloaderImage/PreloaderImage.js";

@ -1,18 +1,15 @@
// PLEASE DO NOT EDIT THIS FILE,
// IF YOU WANT ADD ANY CODE CREATE NEW SCSS INTO client-custom
:root{
--xshop-background:#ffffff;
--xshop-primary:#ff0000;
--xshop-secondary:#8f007c;
--xshop-text:#000000;
--border-radius:99px 0px 0px 27px;
--xshop-shadow:-11px 2px 11px #777777;
--xshop-background:#eeeeee;
--xshop-primary:#6e0000;
--xshop-secondary:#ff0000;
--xshop-text:#111111;
--border-radius:7px;
--xshop-shadow:2px 2px 4px #777777;
}
@import "client-custom/assetsNode";
@import "client-custom/general";
@import "client-custom/zfix";
@import "../views/segments/preloader/PreloaderCircle/PreloaderCircle";
@import "../views/segments/top/TopSimple/TopSimple";
@import "../views/segments/slider/SliderSimple/SliderSimple";
@import "../views/segments/top/TopSimple/TopSimple";
@import "../views/segments/preloader/PreloaderImage/PreloaderImage";

Loading…
Cancel
Save