Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pmochine opened this issue Mar 29, 2022 · 2 comments

Comments

@pmochine
Copy link

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:
#83

Thank you <3

@freekmurze
Copy link
Member

Duplicate of existing discussion.

@pmochine
Copy link
Author

🎉 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);
        });
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants