3

We have updated laravel/framework to version ^9.0 and league/flysystem to ^3.0.

Now we have the following error: Call to undefined method League\Flysystem\Filesystem::put()

Our code: Storage::disk('disk-name')->put($concept->id.'.docx', file_get_contents($tmpPath));

In the flysystem upgrade guide they say: https://flysystem.thephpleague.com/docs/upgrade-from-1.x/

That put() changed to write() method.

When I look in the flysystem source they use:

vendor/league/flysystem/src/Filesystem.php

public function write(string $location, string $contents, array $config = []): void

But when I look in the Laravel 9 Storage facade they still use:

applications/kics/vendor/laravel/framework/src/Illuminate/Support/Facades/Storage.php

put

Also in the laravel 9 documenten they show examples that they suggest to use the put method. https://laravel.com/docs/9.x/filesystem#obtaining-disk-instances

Does anyone have an idea how to solve this?

Thanks!

`

Joost
  • 87
  • 2
  • 5

2 Answers2

1

If you're using custom filesystem disk, you need to make certain changes in Custom Service Provider. Ref: https://laravel.com/docs/9.x/upgrade#flysystem-3

OLD

use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
 
Storage::extend('dropbox', function ($app, $config) {
    $client = new DropboxClient(
        $config['authorization_token']
    );
 
    return new Filesystem(new DropboxAdapter($client));
});

NEW

use Illuminate\Filesystem\FilesystemAdapter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;
 
Storage::extend('dropbox', function ($app, $config) {
    $adapter = new DropboxAdapter(
        new DropboxClient($config['authorization_token'])
    );
 
    return new FilesystemAdapter(
        new Filesystem($adapter, $config),
        $adapter,
        $config
    );
});
Murad Hajiyev
  • 121
  • 1
  • 10
1

In the Laravel documentation it specifies that there are changes with Laravel 8 and 9.

In Laravel 8 a Filesystem is returned

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

but for Laravel 9 a FilesystemAdapter is returned.

return new FilesystemAdapter(
        new Filesystem($adapter, $config),
        $adapter,
        $config
    );

If you use a Provider don't forget to change it.