Hello, laravel web developers! In this article, we'll see how to backup on Dropbox using spatie/flysystem-dropbox in laravel 11. Dropbox is a file hosting service operated by the American company Dropbox, Inc.
Dropbox is a cloud storage solution, equipped with features to help you save time, improve your productivity, and collaborate with others.
You can do with Dropbox include: Store your files, documents, and photos online and access them from any device.
Laravel 11 Store Backup on Dropbox using spatie/flysystem-dropbox
We'll install the laravel 11 application using the following command in this step.
composer create-project laravel/laravel laravel-11-example
Next, we'll install the spatie/flysystem-dropbox composer package to access the Dropbox API using the following command.
composer require spatie/flysystem-dropbox
Then, we'll add Dropbox storage configuration in AppServiceProvider. we'll configure it as a driver in the config/filesystems.php file.
app/Providers/AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Storage::extend('dropbox', function (Application $app, array $config) {
$adapter = new DropboxAdapter(new DropboxClient(
$config['authorization_token']
));
return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
});
}
}
config/filesystems.php
<?php
return [
...
...
'disks' => [
...
'dropbox' => [
'driver' => 'dropbox',
'key' => env('DROPBOX_APP_KEY'),
'secret' => env('DROPBOX_APP_SECRET'),
'authorization_token' => env('DROPBOX_AUTH_TOKEN'),
],
],
]
Next, get the Dropbox API key, secret key, and authorization token to store files on Dropbox.
Creating a new app. After navigating to the developer portal, click App Console.
Add files.content.write permission to your app.
Now, get the API Key, API Secret, and Access token.
Next, add credentials to the .env file.
.env
DROPBOX_APP_KEY=xxxxxx
DROPBOX_APP_SECRET=xxxxxx
DROPBOX_AUTH_TOKEN=xxxxxx
Next, we'll install spatie/laravel-backup composer package to back up the project and store it in Dropbox.
composer require spatie/laravel-backup
Now, publish the laravel backup file using the following command.
php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
config/backup.php
<?php
return [
...
...
'destination' => [
/*
* The disk names on which the backups will be stored.
*/
'disks' => [
'dropbox',
],
],
Now, run the following command to backup laravel application.
php artisan backup:run
You might also like :