I'm trying to integrate spatie media library package to use cloudinary to host and serve images..
the package didnt support cloudinary so I had to use another old package: flysystem-cloudinary
I also followed a discussion on stackoverflow where someone also battled it: spatie-cloudinary
I managed to upload an image to cloudinary but when I'm trying to retrieve it, I get this error:
Declaration of App\Cloudinary\CloudinaryUrlGenerator::getTemporaryUrl(): string must be compatible with Spatie\MediaLibrary\UrlGenerator\UrlGenerator::getTemporaryUrl(DateTimeInterface $expiration, array $options = Array): string
This is my CloudinaryUrlGenerator:
<?php
namespace App\Cloudinary;
use Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator;
class CloudinaryUrlGenerator extends BaseUrlGenerator
{
const HOST = 'https://res.cloudinary.com/';
/**
* Get the url for a media item.
*
* @return string
*/
public function getUrl(): string
{
$cloudBaseUrl = self::HOST . config('filesystems.disks.cloudinary.cloud_name') . '/';
$options = [
'q_auto',
];
$filePathIncludingFilenameAndExtension = '/' . $this->pathGenerator->getPath($this->media) . $this->media->file_name;
return $cloudBaseUrl . implode(',', $options) . $filePathIncludingFilenameAndExtension;
}
/**
* Get the temp url for a media item.
*
* @return string
*/
public function getTemporaryUrl(): string
{
return $this->getUrl();
}
/**
* Get the responsive images directory url for a media item.
*
* @return string
*/
public function getResponsiveImagesDirectoryUrl(): string
{
return $this->getUrl();
}
}
I tried to play with the function definition but it didnt solve it.