Created
October 21, 2023 18:36
Revisions
-
awcodes created this gist
Oct 21, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,88 @@ <?php namespace App\Models; use Awcodes\Curator\Models\Media; use Cloudinary\Cloudinary; use Cloudinary\Transformation\Format; use Cloudinary\Transformation\Quality; use Cloudinary\Transformation\Resize; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Support\Facades\Storage; class CustomMedia extends Media { protected $table = 'media'; protected function url(): Attribute { return new Attribute( get: function() { if ($this->disk === 'cloudinary') { return (string) (new Cloudinary()) ->image($this->path) ->resize(Resize::fit(800)) ->format(Format::auto()) ->quality(Quality::auto()) ->toUrl(); } return Storage::disk($this->disk)->url($this->path); } ); } protected function thumbnailUrl(): Attribute { return Attribute::make( get: function() { if ($this->disk === 'cloudinary') { return (string) (new Cloudinary()) ->image($this->path) ->resize(Resize::crop(200, 200)) ->format(Format::auto()) ->quality(Quality::auto()) ->toUrl(); } return $this->getSignedUrl(['w' => 200, 'h' => 200, 'fit' => 'crop', 'fm' => 'webp']); } ); } protected function mediumUrl(): Attribute { return Attribute::make( get: function() { if ($this->disk === 'cloudinary') { return (string) (new Cloudinary()) ->image($this->path) ->resize(Resize::crop(640, 640)) ->format(Format::auto()) ->quality(Quality::auto()) ->toUrl(); } return $this->getSignedUrl(['w' => 640, 'h' => 640, 'fit' => 'crop', 'fm' => 'webp']); } ); } protected function largeUrl(): Attribute { return Attribute::make( get: function() { if ($this->disk === 'cloudinary') { return (string) (new Cloudinary()) ->image($this->path) ->resize(Resize::crop(1024, 1024)) ->format(Format::auto()) ->quality(Quality::auto()) ->toUrl(); } return $this->getSignedUrl(['w' => 1024, 'h' => 1024, 'fit' => 'contain', 'fm' => 'webp']); } ); } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ <?php return [ ... 'model' => \App\Models\CustomMedia::class, ... ];