Skip to content

Commit

Permalink
feat: Traits and dependencies (#10)
Browse files Browse the repository at this point in the history
* feat: Media library Trait

* refactor: New dependencies installed

* feat: Sluggable Trait

* feat: Overall Trait added
  • Loading branch information
achyutkneupane authored Dec 28, 2023
1 parent 4016adb commit 887b99d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 10 additions & 0 deletions src/Traits/HasTheDashboardTraits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace AchyutN\Dashboard\Traits;

use Dipesh79\LaravelUserLogs\Traits\HasLog;

trait HasTheDashboardTraits
{
use HasTheMedia, HasTheSlug, HasLog;
}
50 changes: 50 additions & 0 deletions src/Traits/HasTheMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace AchyutN\Dashboard\Traits;

use Spatie\Image\Manipulations;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

trait HasTheMedia
{
use InteractsWithMedia;
public function cover()
{
return $this->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();
}
}
18 changes: 18 additions & 0 deletions src/Traits/HasTheSlug.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace AchyutN\Dashboard\Traits;

use Cviebrock\EloquentSluggable\Sluggable;

trait HasTheSlug
{
use Sluggable;
public function sluggable(): array
{
return [
'slug' => [
'source' => 'title'
]
];
}
}

0 comments on commit 887b99d

Please sign in to comment.