diff --git a/src/Traits/HasMedia.php b/src/Traits/HasMedia.php new file mode 100644 index 0000000..e39faae --- /dev/null +++ b/src/Traits/HasMedia.php @@ -0,0 +1,51 @@ +belongsTo(app('image')); + } + + public function ogimage() + { + return $this->belongsTo(app('image'), 'ogimage_id'); + } + + public function video() + { + return $this->belongsTo(app('video')); + } + + /** + * Get a string path for the page image. + * + * @return UrlGenerator|string + */ + public function getImagePathAttribute() + { + $cloudName = config('filesystem.disks.cloudinary.cloud_name'); + + return $this->image === null + ? url('img/ogimage.jpg') + : "https://res.cloudinary.com/{$cloudName}/t_cover/{$this->image->filename}"; + } + + /** + * Get a string path for the page image's placeholder. + * + * @return UrlGenerator|string + */ + public function getPlaceholderPathAttribute() + { + $cloudName = config('filesystem.disks.cloudinary.cloud_name'); + + return $this->image === null + ? url('img/ogimage.jpg') + : "https://res.cloudinary.com/{$cloudName}/t_coverplaceholder/{$this->image->filename}"; + } +}