📝 Add getResponsiveImagesDirectoryUrl in TenantAwareUrlGenerator

This commit is contained in:
AhmedSobhy01 2024-08-10 12:38:50 +03:00
parent f5eb95e16b
commit dc324488fb

View file

@ -72,10 +72,11 @@ The reason for this is that spatie/laravel-permission caches permissions & roles
## **laravel-medialibrary** {#laravel-medialibrary} ## **laravel-medialibrary** {#laravel-medialibrary}
To generate the correct media URLs for tenants, create a custom URL generator class extending `Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator` and override the `getUrl()` method: To generate the correct media URLs for tenants, create a custom URL generator class extending `Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator` and override the `getUrl()` method and the `getResponsiveImagesDirectoryUrl` method that is used for generating URLs of responsive images.
```php ```php
use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator; use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator;
use Illuminate\Support\Str;
class TenantAwareUrlGenerator extends DefaultUrlGenerator class TenantAwareUrlGenerator extends DefaultUrlGenerator
{ {
@ -87,6 +88,13 @@ class TenantAwareUrlGenerator extends DefaultUrlGenerator
return $url; return $url;
} }
public function getResponsiveImagesDirectoryUrl(): string
{
$path = $this->pathGenerator->getPathForResponsiveImages($this->media);
return Str::finish(tenant_asset($path), '/');
}
} }
``` ```