Laravel Dropbox Driver package: how to install and use it

Benjamin Crozat Benjamin Crozat4 minutes read

Table of contents

Laravel Dropbox Driver package: how to install and use it

Adding a new disk in the storage is easy. The only things I did was:

Requirements

Laravel Dropbox Driver requires:

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

Apps creation on Dropbox.

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:

How to create a custom storage driver in Laravel?

To create a custom storage driver in Laravel, you will need to do the following:

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');

Recommended

Learning a framework can be overwhelming, but time and execution will make you a master. Here are some best practices to help you toward your goal.

Laravel Collections make arrays more powerful and convenient to work with. This article provides tons of quick tips to instantly make your codebase better.

switch, case, and break. What are all these? When should you use it instead of if? What are its pros and cons?

Debugging requires dissecting everything. Here's a list of all the one-line of code built-in ways to print arrays in PHP (and even Laravel-specific helpers).

Nailing a Laravel job interview can be a daunting task, but with the right preparation and mindset, you can set yourself up for success.

Start leveraging the power of AI, today. AI enables developers to do incredible things, and many startups build products around it.

Laravel 10 will be released on February 7, 2023. Its development is still ongoing. Let's dive into every relevant new feature we know about already.

There are multiple ways to check if an array is empty. Let me tell you about each of them and why and when you should use them.

Take your code to the next level, thanks to exceptions. Handle errors in a more graceful way within try and catch blocks.

Have you heard about Laravel but don't know where to start? Don't worry; you just found the best starting point for your journey.

Powered by