Laravel Dropbox Driver package: how to install and use it
Table of contents

Adding a new disk in the storage is easy. The only things I did was:
- Copy and paste code from the documentation and made it a package (https://laravel.com/docs/filesystem#custom-filesystems)
- Use the Flysystem adapter from Spatie, which Laravel is based on (https://github.com/spatie/flysystem-dropbox)
Requirements
Laravel Dropbox Driver requires:
- PHP 8.1+
- Laravel 9+
Installation
To install Laravel Dropbox Driver, run the command below:
composer require benjamincrozat/laravel-dropbox-driver
Usage in your project
Add the following in app/filesystems.php:
'disks' => [ 'dropbox' => [ 'driver' => 'dropbox', 'token' => env('DROPBOX_TOKEN'), ], ],
Then, in your .env file:
DROPBOX_TOKEN=your_access_token
Get a token from Dropbox
Log in to your Dropbox account and create a new application to generate your access token.
https://www.dropbox.com/developers/apps/create
License
Take this package and do whatever the f you want with it. That’s basically what the WTFPL license says.
What can you do with Laravel Dropbox Driver?
The Laravel Dropbox Driver package allows you to use storage anything you’d like on Dropbox from your Laravel applications. Here are some example use cases I could think about:
- Automatically back up your Laravel application’s files and database. This can provide an additional layer of protection in case of server failure or data loss. Take a look at spatie/laravel-backups.
- I’ve never tried this, but you could totally store user-generated files, such as photos and documents, in a Dropbox account. This can be useful if you want to provide your users a way to manage their own files, or if you need to store files that exceed your local storage capacity.
How to create a custom storage driver in Laravel?
To create a custom storage driver in Laravel, you will need to do the following:
- Create a new class that extends the
Illuminate\Contracts\Filesystem\Filesystem
contract. This class should implement all of the methods defined in the contract, such asput()
,get()
, anddelete()
. - In your new class, you can implement custom logic for storing and retrieving files using whatever storage system you prefer, such as a local filesystem, a remote FTP server, or a cloud storage service like Amazon S3.
- Once you have implemented your custom storage driver, you can register it with Laravel by adding an entry to the disks array in the config/filesystems.php configuration file. This entry should specify the driver’s class name and any configuration options that your driver requires.
- Finally, you can use your custom storage driver in your Laravel application. Use the
Storage
facade for ease-of-use.
Here’s an example of what a custom storage driver class looks like:
namespace App\Filesystem; use Illuminate\Contracts\Filesystem\Filesystem; class CustomStorage implements Filesystem{ public function put($path, $contents, $visibility = null) { // Implement custom logic for storing a file... } public function get($path) { // Implement custom logic for retrieving a file... } public function delete($path) { // Implement custom logic for deleting a file... } // Implement other methods from the Filesystem contract...}
You can then register your custom storage driver in the config/filesystems.php configuration file like this:
'disks' => [ 'custom' => [ 'driver' => App\Filesystem\CustomStorage::class, 'key' => 'your-api-key', 'secret' => 'your-api-secret', ],],
And finally, you can use your custom storage driver in your Laravel code like this:
use Illuminate\Support\Facades\Storage; // Use the "custom" disk...Storage::disk('custom')->put('file.txt', 'Contents');