Powered by Cloudflare R2

Introduction

Laravel Cloud allows you to create S3-compatible object storage buckets and attach them to your application’s environments directly from the Laravel Cloud dashboard. Laravel Cloud Object Storage is offered in partnership with Cloudflare R2.

Laravel Cloud Object Storage may be used as your Laravel application’s file storage backend, allowing you to interact with the bucket via Laravel’s Storage facade.

Prerequisites

Before utilizing Laravel Object Storage, you should ensure your application includes the league/flysystem-aws-s3-v3 package in its composer.json dependencies:

composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies

Creating Buckets

To attach a Laravel Object Storage bucket to an environment, click “Add bucket” on your environment’s infrastructure canvas dashboard. When adding a bucket to an environment, Laravel Cloud will prompt you to select the bucket you would like to attach to the environment or to create a new bucket.

When creating a new bucket, select “Laravel Object Storage” as your bucket type.

Once the bucket has been attached to an environment, you will need to re-deploy the environment in order for the changes to take effect.

Visit the pricing docs for information on compute and storage prices.

Bucket Disk Names

When creating a bucket, you will also be prompted to provide a “disk name”. This name corresponds to the name you will use when accessing the bucket / disk via Laravel’s Storage facade:

return Storage::disk('r2')->get('photo.jpg');

You will also be able to indicate if the disk should be the “default” disk for the Laravel application. When a bucket is the default disk, you do not need to provide its name when accessing it via Laravel’s Storage facade:

return Storage::get('photo.jpg');

Bucket File Visibility

When creating a bucket, you will be prompted to select the bucket’s file visibility. All files added to the bucket will receive the specified visibility, and Laravel Cloud Object Storage buckets do not support mixing file visibility settings within a single bucket.

  • Private buckets: all files within the bucket are private and are not publicly accessible via the Internet. However, temporary public URLs may be generated to files within these buckets using the Storage::temporaryUrl method offered by Laravel. These buckets are typically used for private assets like personal documents uploaded by your application’s users.

  • Public buckets: all files within the bucket are public and are publicly accessible via the Internet via a Laravel Cloud provided URL. These buckets are typically used for publicly viewable assets like user avatars.

Connecting to Buckets

From Your Application

When a bucket is attached to an environment, Laravel Cloud will automatically inject the environment variables needed by the Laravel application to interact with the bucket via the Storage facade, including the FILESYSTEM_DISK and AWS S3-compatible bucket related variables. You may view these environment variables in your environment’s General Settings.

From Your Local Machine

To connect to your bucket from your local machine using a Cloudflare R2 compatible bucket management client like Cyberduck, click the ”…” icon next to the bucket card in your environment’s infrastructure canvas dashboard, then click “View credentials”.

The bucket credentials modal window will provide you with the credentials needed to connect to your bucket. When connecting to the bucket via a bucket management client, you will likely need to indicate that bucket is an Amazon S3 compatible bucket, even though it is powered by Cloudflare R2.

Editing Buckets

You may edit Laravel Object Storage buckets via your organization’s “Resources” page. From the “Resources” page, navigate to the “Object storage” tab and click the ”…” icon for the bucket you would like to edit. Then, click “Edit settings”.

Deleting Buckets

You may delete a Laravel Object Storage bucket via your organization’s “Resources” page. From the “Resources” page, navigate to the “Object storage” tab and click the ”…” icon for the bucket you would like to delete. Then, click “Delete bucket”.

Was this page helpful?