From 887b99d4845510e8950fc00aa9b82b7067cd9e4f Mon Sep 17 00:00:00 2001 From: Achyut Neupane <30431426+achyutkneupane@users.noreply.github.com> Date: Thu, 28 Dec 2023 23:41:42 +0545 Subject: [PATCH] feat: Traits and dependencies (#10) * feat: Media library Trait * refactor: New dependencies installed * feat: Sluggable Trait * feat: Overall Trait added --- composer.json | 6 ++++ src/Traits/HasTheDashboardTraits.php | 10 ++++++ src/Traits/HasTheMedia.php | 50 ++++++++++++++++++++++++++++ src/Traits/HasTheSlug.php | 18 ++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/Traits/HasTheDashboardTraits.php create mode 100644 src/Traits/HasTheMedia.php create mode 100644 src/Traits/HasTheSlug.php diff --git a/composer.json b/composer.json index 03e2fc5..be49823 100644 --- a/composer.json +++ b/composer.json @@ -4,9 +4,15 @@ "php": "^7.3|^8.0", "livewire/livewire": "^2.12.6|^3.3.1", "rappasoft/laravel-livewire-tables": "^3.1.5|^2.15.0", + "spatie/image": "^3.3.2", "spatie/laravel-medialibrary": "^11.0.0", "laravel/framework": "^v10.38.0", "laravel/ui": "^4.3.0", + "barryvdh/laravel-debugbar": "^3.9", + "spatie/laravel-sluggable": "^3.5", + "spatie/laravel-permission": "^6.3", + "rap2hpoutre/laravel-log-viewer": "^2.3", + "dipesh79/laravel-user-logs": "^1.4", "ext-json": "*" }, "autoload": { diff --git a/src/Traits/HasTheDashboardTraits.php b/src/Traits/HasTheDashboardTraits.php new file mode 100644 index 0000000..99c3a5a --- /dev/null +++ b/src/Traits/HasTheDashboardTraits.php @@ -0,0 +1,10 @@ +getMedia('cover')->count() ? $this->getMedia('cover')->last()->getUrl() : null; + } + + public function small_cover() + { + return $this->getMedia('cover')->count() ? $this->getMedia('cover')->last()->getUrl('small') : null; + } + + public function medium_cover() + { + return $this->getMedia('cover')->count() ? $this->getMedia('cover')->last()->getUrl('medium') : null; + } + + public function big_cover() + { + return $this->getMedia('cover')->count() ? $this->getMedia('cover')->last()->getUrl('big') : null; + } + + public function registerMediaConversions(Media $media = null): void + { + $this->addMediaConversion('small') + ->format(Manipulations::FORMAT_WEBP) + ->width(150) + ->height(80) + ->nonQueued(); + $this->addMediaConversion('medium') + ->format(Manipulations::FORMAT_WEBP) + ->width(300) + ->height(160) + ->nonQueued(); + $this->addMediaConversion('big') + ->format(Manipulations::FORMAT_WEBP) + ->width(800) + ->height(420) + ->nonQueued(); + } +} \ No newline at end of file diff --git a/src/Traits/HasTheSlug.php b/src/Traits/HasTheSlug.php new file mode 100644 index 0000000..354721a --- /dev/null +++ b/src/Traits/HasTheSlug.php @@ -0,0 +1,18 @@ + [ + 'source' => 'title' + ] + ]; + } +} \ No newline at end of file