This commit is contained in:
Ahmed Sobhy 2025-10-28 18:07:15 +03:00 committed by GitHub
commit a21ec133cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -72,10 +72,11 @@ The reason for this is that spatie/laravel-permission caches permissions & roles
## **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
use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator;
use Illuminate\Support\Str;
class TenantAwareUrlGenerator extends DefaultUrlGenerator
{
@ -87,6 +88,13 @@ class TenantAwareUrlGenerator extends DefaultUrlGenerator
return $url;
}
public function getResponsiveImagesDirectoryUrl(): string
{
$path = $this->pathGenerator->getPathForResponsiveImages($this->media);
return Str::finish(tenant_asset($path), '/');
}
}
```