setting up multiple database tenancy with AWS S3 using Cloudfront together with spatie/media-library #480
MattWiseParking
started this conversation in
Ideas
Replies: 2 comments
-
currently receive the following error when I run
App\Multitenancy\PrefixStorageTask::setDefaultDisk(): Argument #1 ($disk) must be of type string, null given, called in /var/app/current/app/Multitenancy/PrefixStorageTask.php on line 42 |
Beta Was this translation helpful? Give feedback.
0 replies
-
fixed, change line 18 from
to
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Lets say you have a multi tenancy database setup in laravel 10 and you want to store all your assets on a s3 bucket utilising cloudfront and spatie/media-library setup. One approach would be to manually setup a disk in the config/filesystems.php file for each tenant, which would be a bit too cumbersome.
The approach I took, was to use the same s3 bucket for all tenants, setting up a new disk and to prefix the path of the new disk with 'tenant_{id}' where id is the tenant id of the table tenants. Let me show you the process and code I used:
Prerequisites
I assume that you have the following setup/installed:
The Process
refresh the config
php artisan config:cache
That should now set you up with all the assets pointing to the s3 bucket. When you add any files using spatie/media-library, the root of the s3 bucket should be: tenant_1/{id}/...
The Landlord will automatically default back to its original settings, if the original settings are the s3 bucket then it will add the folders as {id}/... as usual
I hope this document helps out somebody. The only thing I have not mentioned is the same assets url will be used as you setup against the dns/cloudfront. for example: assets.my-domain.com would point to all s3 buckets. If you wanted the AWS_URL to change then I guess you could manipulate the above class we created in step 2 to include this.
Beta Was this translation helpful? Give feedback.
All reactions