Src URL uses set url generator, but srcset URLs do not? #3675
Replies: 3 comments
-
Additional info: if (isset($this->config['url'])) {
return $this->concatPathToUrl($this->config['url'], $path);
}
|
Beta Was this translation helpful? Give feedback.
-
Are src and srcset using different path generators? I'm running out of ideas on this one. |
Beta Was this translation helpful? Give feedback.
-
The directory URL for responsive images is generated using The solution would be to override this function too in your <?php
namespace App\Services;
use Spatie\LaravelSettings\Support;
use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator;
use Illuminate\Support\Str;
class TenantAwareUrlGenerator extends DefaultUrlGenerator
{
public function getUrl(): string
{
$url = tenant_asset($this->getPathRelativeToRoot());
$url = $this->versionUrl($url);
return $url;
}
public function getResponsiveImagesDirectoryUrl(): string
{
$path = $this->pathGenerator->getPathForResponsiveImages($this->media);
return Str::finish(tenant_asset($path), '/');
}
} |
Beta Was this translation helpful? Give feedback.
-
Hi. I'm using spatie/laravel-medialibrary 11.7.6 and stancl/tenancy 3.8.4, and my goal here is to make them work together.
I've edited config/media-library.php:
..and the code for TenantAwareUrlGenerator looks like this:
When "fetching" the HTML for the media image I do this:
$item->getFirstMedia('mymediacollection')?->toHtml();
..where $item is an instance of a class with the default medialibrary Media linked to it in the database.
Problem is, the src in the
<img>
is tenant aware, i.e the URL ishttp://mysite.localhost/...
which is correct. In the srcset the URLs arehttp://localhost/...
.Stepping through things I see this:
responsiveImageWithPlaceholder.blade.php
contains this:$media->getUrl()
uses the tenant aware Url Generator configured earlier, but$media->getSrcset($conversion)
doesn't.If needed I'll of course paste any extra info needed. Tbh I'm not sure whether to ask about this here or in the Tenancy for laravel forum, I hope I'm not offending anyone.
Beta Was this translation helpful? Give feedback.
All reactions