Skip to content

Commit

Permalink
Add spatie/laravel-medialibrary integration guide (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukinovec authored Sep 1, 2022
1 parent 4c7eeb9 commit aca5b15
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions source/docs/v3/integrations/spatie.blade.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,29 @@ Event::listen(TenancyEnded::class, function (TenancyEnded $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,
```

0 comments on commit aca5b15

Please sign in to comment.