spatie / flysystem-dropbox

A flysystem driver for Dropbox that uses the v2 API
https://freek.dev/734-dropbox-will-turn-off-v1-of-their-api-soon-its-time-to-update-your-php-application
MIT License
342 stars 50 forks source link

Updated to Laravel 9: Argument #1 ($disk) must be of type ?Illuminate\Contracts\Filesystem\Filesystem, League\Flysystem\Filesystem given, #84

Closed pmochine closed 2 years ago

pmochine commented 2 years ago

I updated my Laravel but I get the error when I try to backup.

production.ERROR: Spatie\Backup\BackupDestination\BackupDestination::__construct(): Argument #1 ($disk) must be of type ?Illuminate\Contracts\Filesystem\Filesystem, League\Flysystem\Filesystem given, called in /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestination.php on line 60 {"exception":"[object] (TypeError(code: 0): Spatie\\Backup\\BackupDestination\\BackupDestination::__construct(): Argument #1 ($disk) must be of type ?Illuminate\\Contracts\\Filesystem\\Filesystem, League\\Flysystem\\Filesystem given, called in /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestination.php on line 60 at /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestination.php:23)
[stacktrace]
#0 /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestination.php(60): Spatie\\Backup\\BackupDestination\\BackupDestination->__construct()
#1 /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestinationFactory.php(12): Spatie\\Backup\\BackupDestination\\BackupDestination::create()
#2 [internal function]: Spatie\\Backup\\BackupDestination\\BackupDestinationFactory::Spatie\\Backup\\BackupDestination\\{closure}()
#3 /var/www/mywebsite-staging/releases/12/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(721): array_map()
#4 /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/BackupDestination/BackupDestinationFactory.php(12): Illuminate\\Support\\Collection->map()
#5 /var/www/mywebsite-staging/releases/12/vendor/spatie/laravel-backup/src/Tasks/Backup/BackupJobFactory.php(16): Spatie\\Backup\\BackupDestination\\BackupDestinationFactory::createFromArray()

I'm using a DropboxServiceProvider to extend the Storage for Dropbox

<?php

namespace App\Providers;

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

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorization_token']
            );

            return new Filesystem(new DropboxAdapter($client), ['case_sensitive' => false]);
        });
    }
}

Besides that I saw that another person has the issue: https://github.com/spatie/flysystem-dropbox/discussions/83

Thank you <3

freekmurze commented 2 years ago

Duplicate of existing discussion.

pmochine commented 2 years ago

🎉 I just found a solution, because I looked up an alternative to dropbox. I found about google drive and looked up their code for Laravel. And there I found the solution:

The whole code so dropbox is working again:

<?php

namespace App\Providers;

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

class DropboxServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorization_token']
            );

            $adapter = new DropboxAdapter($client);
            $driver = new Filesystem($adapter, ['case_sensitive' => false]);

            return new FilesystemAdapter($driver, $adapter);
        });
    }
}