Recently we use Spatie laravel-multitenancy package in our of our client’s CRM project along with spatie/laravel-medialibrary. The default behavior of the media library package is, it generates a folder for each media with its ID in our configured disk, like a public folder or s3 or whatever disk we configured.
So what we want to do is, instead of having a structure like, What we want to achieve is, we want to have a folder structure where media of every tenant will be in a separate folder with tenant unique id, Spatie Media library is very configurable out of the box where you can write your own media library path generator.
Here is how it looks like, What we did here is, we just simply extended the Spatie\MediaLibrary\Support\PathGenerator\DefaultPathGenerator of Media Library and override the function getBasePath.
All you need to make sure is, whenever you are uploading a media, your application should be tenant aware.