【问题标题】:Call to undefined method League\Flysystem\Filesystem::put()调用未定义的方法 League\\Flysystem\\Filesystem::put()
【发布时间】:2022-09-29 12:48:17
【问题描述】:

我们已将 laravel/framework 更新到 ^9.0 版本,将 League/flysystem 更新到 ^3.0。

现在我们有以下错误: Call to undefined method League\\Flysystem\\Filesystem::put()

我们的代码: Storage::disk(\'disk-name\')->put($concept->id.\'.docx\', file_get_contents($tmpPath));

在 flysystem 升级指南中,他们说: https://flysystem.thephpleague.com/docs/upgrade-from-1.x/

那个 put() 变成了 write() 方法。

当我查看他们使用的 flysystem 源代码时:

vendor/league/flysystem/src/Filesystem.php

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

但是当我查看 Laravel 9 Storage 外观时,他们仍然使用:

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

put

同样在 laravel 9 文档中,他们展示了他们建议使用 put 方法的示例。 https://laravel.com/docs/9.x/filesystem#obtaining-disk-instances

有谁知道如何解决这个问题?

谢谢!

`

    标签: laravel flysystem


    【解决方案1】:

    如果您使用自定义文件系统磁盘,则需要在自定义服务提供程序中进行某些更改。

    老的

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

    新的

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

    【讨论】:

      猜你喜欢
      • 2021-03-14
      • 1970-01-01
      • 2020-09-02
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 2017-12-09
      • 2018-01-19
      相关资源
      最近更新 更多