Components
Media Library
Integrations
Tenancy
If your codebase uses multi-tenancy, you need to ensure that the Media Library is aware of the current tenant when performing operations. Depending on your chosen driver, there are multiple approaches to achieve this.
MediaLibraryItem-driver
When using the Spatie Media Library Item Driver in a multi-tenant application, you need to ensure that the Media Library is aware of the current tenant when performing operations. This can be achieved by enabling tenancy on the driver.
Media items are linked to tenants through tenant_* morph columns on the filament_media_library and filament_media_library_folders tables. When tenancy is enabled, the driver will automatically filter media items based on the current tenant.
Enabling tenancy
To enable tenancy, call the ->tenancy() method on the $driver:
In a future major version, tenancy will be automatically enabled based on your panel's tenancy status.
Troubleshooting
If you encounter the following error:
You are probably missing the V4 tenancy migration. Publish the migrations and run them:
Configuring tenant directory
When using the Filesystem Storage Driver in a multi-tenant application, you can configure tenancy by dynamically setting the ->directory() based on the current tenant.
To isolate media files per tenant, pass a closure to the driver configuration that sets the ->directory() based on the current tenant: