mirror of
https://github.com/stancl/tenancy-docs.git
synced 2025-12-12 10:14:03 +00:00
Add spatie/laravel-medialibrary integration guide
This commit is contained in:
parent
af05970907
commit
02f6f071fa
1 changed files with 26 additions and 0 deletions
|
|
@ -38,3 +38,29 @@ Event::listen(TenancyBootstrapped::class, function (TenancyBootstrapped $event)
|
|||
```
|
||||
|
||||
The reason for this is that spatie/laravel-permission caches permissions & roles to save DB queries, which means that we need to separate the permission cache by tenant.
|
||||
|
||||
## **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:
|
||||
|
||||
```php
|
||||
use Spatie\MediaLibrary\Support\UrlGenerator\DefaultUrlGenerator;
|
||||
|
||||
class TenantAwareUrlGenerator extends DefaultUrlGenerator
|
||||
{
|
||||
public function getUrl(): string
|
||||
{
|
||||
$url = asset($this->getPathRelativeToRoot());
|
||||
|
||||
$url = $this->versionUrl($url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then, change the `url_generator` in the media-library config to the custom one (make sure to import it):
|
||||
|
||||
```php
|
||||
'url_generator' => TenantAwareUrlGenerator::class,
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue