Search code examples
phplaraveldropboxservice-providerlaravel-storage

Laravel Storage::extend not working


I can't figure out where I'm going wrong, with this. I've followed the Laravel docs by installing spatie/flysystem-dropbox via composer copied the DropboxServiceProvider from the Laravel Docs, added the service provided to the config\app.php, ran composer dump autoload but yet I am still getting the following error message:

PHP error:  Undefined index: driver in /***/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php on line 112

Here is the service provider:

<?php

namespace App\Providers;

use Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Illuminate\Support\ServiceProvider;
use Spatie\FlysystemDropbox\DropboxAdapter;

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorizationToken']
            );

            return new Filesystem(new DropboxAdapter($client));
        });
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

And here's my config/app/php:

...
        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        App\Providers\DropboxServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,

...

Finally, here's my config/filesystems.php:

'dropbox'=>[
            'authorizationToken'=>env('DROPBOX_ACCESS_TOKEN')
        ],

Solution

  • Turns out that I was missing the driver value in the config/filesystems/php so it should have been this:

    'dropbox'=>[
                'driver' => 'dropbox',  <=== THIS WAS MISSING
                'authorizationToken'=>env('DROPBOX_TOKEN')
            ],