From 11bcfe5d5acba2e891492cce451489fe81c49e84 Mon Sep 17 00:00:00 2001 From: A1Gard Date: Fri, 7 Jul 2023 08:01:19 +0330 Subject: [PATCH] customize thumbnail size fixed some error fixed file template --- .env.example | 3 +- app/Helpers/Helper.php | 2 +- app/Models/Cat.php | 39 ++++++++++++------- app/Models/Product.php | 9 +++-- app/Models/User.php | 2 + config/app.php | 7 ++-- .../views/component/home_jsonld.blade.php | 4 +- 7 files changed, 42 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index c6a6c06..ddba5b7 100755 --- a/.env.example +++ b/.env.example @@ -57,9 +57,10 @@ PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1 - MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" ZARINPAL_MERCHANT='12000000-0220-0000-0220-220000000001' PAY_GATWAY=zarinpal + +THUMBNAIL_SIZE=600x600 diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index f6e531d..5ac3e9e 100755 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -347,7 +347,7 @@ function getProductByCat($id, $order = 'id', $orderMethod = 'desc', $limit = 10) if ($cat == null){ return []; } - return $cat->products()->where('active',1) + return $cat->active_products()->where('active',1) ->orderBy($order, $orderMethod)->limit($limit)->get(); } function getProductByCatQ($id, $order = 'id', $limit = 10) diff --git a/app/Models/Cat.php b/app/Models/Cat.php index 58e9687..bc4e0d3 100755 --- a/app/Models/Cat.php +++ b/app/Models/Cat.php @@ -57,16 +57,18 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media; */ class Cat extends Model implements HasMedia { - use HasFactory,SoftDeletes, InteractsWithMedia; + use HasFactory, SoftDeletes, InteractsWithMedia; public function registerMediaConversions(Media $media = null): void { + $size = explode('x', config('app.thumbnail_size')); + $this->addMediaConversion('cat-thumb') - ->width(600) - ->height(600) - ->crop(Manipulations::CROP_CENTER, 600, 600) + ->width($size[0]) + ->height($size[1]) + ->crop(Manipulations::CROP_CENTER, $size[0], $size[1]) ->optimize() ->sharpen(10); @@ -75,7 +77,8 @@ class Cat extends Model implements HasMedia } } - public function thumbUrl() { + public function thumbUrl() + { if ($this->getMedia()->count() > 0) { return $this->getMedia()->first()->getUrl('cat-thumb'); } else { @@ -84,7 +87,8 @@ class Cat extends Model implements HasMedia } } - public function imgurl() { + public function imgurl() + { if ($this->getMedia()->count() > 0) { return $this->getMedia()->last()->getUrl(); } else { @@ -92,11 +96,14 @@ class Cat extends Model implements HasMedia } } - public function products(){ - return$this->belongsToMany(Product::class); + public function products() + { + return $this->belongsToMany(Product::class); } - public function active_products(){ - return$this->belongsToMany(Product::class)->where(''); + + public function active_products() + { + return $this->belongsToMany(Product::class)->where('active', 1); } public function backUrl() @@ -109,19 +116,23 @@ class Cat extends Model implements HasMedia } // - public function parent() { + public function parent() + { return $this->belongsTo(Cat::class, 'parent_id'); } - public function children() { + public function children() + { return $this->hasMany(Cat::class, 'parent_id'); } - public function getRouteKeyName() { + public function getRouteKeyName() + { return 'slug'; } - public function props(){ + public function props() + { return $this->belongsToMany(Prop::class); } } diff --git a/app/Models/Product.php b/app/Models/Product.php index 768bee6..905a6a5 100755 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -167,16 +167,19 @@ class Product extends Model implements HasMedia public function registerMediaConversions(Media $media = null): void { + $size = explode('x', config('app.thumbnail_size')); + $this->addMediaConversion('product-image') ->width(1200) // ->height(600) // ->crop(Manipulations::CROP_CENTER, 1200, 600) ->optimize() ->sharpen(10); + $this->addMediaConversion('product-thumb') - ->width(600) - ->height(600) - ->crop(Manipulations::CROP_CENTER, 600, 600) + ->width($size[0]) + ->height($size[1]) + ->crop(Manipulations::CROP_CENTER, $size[0], $size[1]) ->optimize() ->sharpen(10); } diff --git a/app/Models/User.php b/app/Models/User.php index 25ed94d..7401995 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -56,6 +56,8 @@ use Xmen\StarterKit\Models\StarterKit; * @property-read int|null $products_count * @property-read \Illuminate\Database\Eloquent\Collection $accesses * @property-read \Illuminate\Database\Eloquent\Collection $products + * @property-read \Illuminate\Database\Eloquent\Collection $accesses + * @property-read \Illuminate\Database\Eloquent\Collection $products * @mixin \Eloquent */ class User extends Authenticatable diff --git a/config/app.php b/config/app.php index 8b00877..7ef219f 100755 --- a/config/app.php +++ b/config/app.php @@ -58,14 +58,15 @@ return [ 'asset_url' => env('ASSET_URL'), - 'currency_type' => env('CURRENCY_TYPE'), - 'invoice_prefix' => env('INVOICE_PREFIX'), + 'currency_type' => env('CURRENCY_TYPE','$'), + 'invoice_prefix' => env('INVOICE_PREFIX','xshop-000'), 'sms_signup' => env('SIGNUP_SMS',false), 'sms_url' => env('SMS_URL'), 'sms_user' => env('SMS_USER'), 'sms_pass' => env('SMS_PASS'), 'sms_number' => env('SMS_NUMBER'), - 'pay_gate' => env('PAY_GATWAY'), + 'pay_gate' => env('PAY_GATWAY','zarinpal'), + 'thumbnail_size' => env('THUMBNAIL_SIZE','600x600'), /* |-------------------------------------------------------------------------- diff --git a/resources/views/component/home_jsonld.blade.php b/resources/views/component/home_jsonld.blade.php index d75b7e4..152f2e6 100755 --- a/resources/views/component/home_jsonld.blade.php +++ b/resources/views/component/home_jsonld.blade.php @@ -3,11 +3,11 @@ { "@context": "http://schema.org", "@type": "WebSite", - "url": "https://shop.ir/", + "url": "{{config('app.url')}}", "name": "{{\SEOMeta::getTitle()}}", "author": { "@type": "Person", - "name": "gold" + "name": "{{config('app.name')}}", }, "description": "{{\SEOMeta::getTitle()}}" }