Laravel 9 Dropbox

Laravel 9 Dropbox Store Backup using Spatie

Laravel 9 Dropbox Store Backup using Spatie

In this post, we will give you information about Laravel 9 Dropbox Store Backup using Spatie. Here we will give you detail about Laravel 9 Dropbox Store Backup using Spatie And how to use it also give you a demo for it if it is necessary.

Laravel 9 Dropbox backup tutorial; In this tutorial, we will teach you how to backup the laravel application and store the laravel app backup on Dropbox.

This guide will make you able to integrate Dropbox in Laravel for storing laravel app backup, and the Spatie package will surely help you in this journey.

How to Save Laravel 9 App Backup on Dropbox Storage
Step 1: Install Laravel Project
Step 2: Add Database Credentials
Step 3: Install Laravel Spatie
Step 4: Get Dropbox Access Token
Step 5: Configure Dropbox FileSystem
Step 6: Add Dropbox Access Key
Step 7: Clear Config Cache
Step 8: Take Backup and Store it on Dropbox
Install Laravel Project
In the first step, you have to install the composer on your system, and create a laravel application using the composer command.

composer create-project laravel/laravel --prefer-dist laravel-9-app

Get inside the project.

cd laravel-9-app

Configure Database Connection

The database configuration of Laravel services is located in the application’s .env configuration file.

You have to open this file, and insert the database name, username, and password.

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=root
DB_PASSWORD=
PL/SQL

Install Laravel Spatie
Next, you can dynamically install the Laravel Spatie package via composer using this command.

composer require spatie/laravel-backup

After taking backup, Spatie sends the confirmation mail related to backup; you need to add the email to receive a confirmation mail in response to laravel backup.

Add the mail address in the MAIL_FROM_ADDRESS variable:

MAIL_FROM_ADDRESS=demo@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

In the next step, we will run a command to publish the Spatie package separately.

php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"

Above vendor publish command, published a new config/backup.php file in this file; in this file, you have to set backup values.

For instance, set the dropbox name to disk property; this is the disk name that will store your backup.

<?php return [ 'destination' => [
            /*
             * The disk names on which the backups will be stored.
             */
            'disks' => [
                'dropbox',
            ],
        ],

Get Dropbox Access Token

In this Laravel dropbox example, you will require a Dropbox access token, and we will show you how to get a dropbox access token from the Dropbox dashboard.

You need to go to the Dropbox admin console and make sure to create a new project.

You will see “Generated access token” button, you have to click on it to generate and get the Dropbox access token.

Laravel Dropbox Backup Examle

Configure Dropbox FileSystem
Next, you can quickly install the spatie flysystem-dropbox package via composer.

composer require spatie/flysystem-dropbox

Next, run PHP artisan make command to publish dropbox service provider.

php artisan make:provider DropboxServiceProvider

Open the app/config/app.php file, add the dropbox service provider class into the providers’ array.

'providers' => [
    ...
    ...
    ...
    App\Providers\DropboxDriveServiceProvider::class,
];

Open the app/Providers/DropboxServiceProvider.php file, and you have to update the boot function inside the provider class.

<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['add_authorization_token']
            );
  
            return new Filesystem(new DropboxAdapter($client));
        });
    }
}

Add Dropbox Access Key

In the last step, we have to add dropbox in laravel, and this mutual consent requires auth key, callback url and client id to be added into the config/filesystem.php file.

<?php return [ ... 'disks' => [
    
        ...
    
        'dropbox' => [
            'driver' => 'dropbox',
            'key' => env('DROPBOX_APP_KEY'),
            'secret' => env('DROPBOX_APP_SECRET'),
            'authorization_token' => env('DROPBOX_ACCESS_TOKEN'),
        ],
    
    ],
];

In the final step, you have to open the .env file and, in this file, add the dropbox auth token.

DROPBOX_AUTH_TOKEN=<dropbox_auth_token>

Clear Config Cache
Let us first clear the config cache, and execute the command from the terminal.

php artisan config:clear

Take Backup and Store it on Dropbox
Eventually, you have to run the command to take the backup and store it in dropbox in this last step.

php artisan backup:run

Conclusion for Laravel 9 Dropbox Store Backup using Spatie

Hope this code and post will help you implement Laravel 9 Dropbox Store Backup using Spatie. if you need any help or any feedback give it in the comment section or if you have a good idea about this post you can give it in the comment section. Your comment will help us to help you more and improve us.

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  86  =  90

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US