我们已经将laravel/framework更新到^9.0版本,将league/flysystem更新到^3.0版本。
现在我们有以下错误:Call to undefined method LeagueFlysystemFilesystem::put()
我们的代码:Storage::disk('disk-name')->put($concept->id.'.docx', file_get_contents($tmpPath));
在飞行系统升级指南中,他们说:https://flysystem.thephpleague.com/docs/upgrade-from-1.x/
那个put((改为write((方法。
当我查看飞行系统的来源时,他们使用:
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-磁盘实例
有人知道如何解决这个问题吗?
谢谢!
`
如果您使用自定义文件系统磁盘,则需要在custom Service Provider中进行某些更改。参考编号:https://laravel.com/docs/9.x/upgrade#flysystem-3
旧
use IlluminateSupportFacadesStorage;
use LeagueFlysystemFilesystem;
use SpatieDropboxClient as DropboxClient;
use SpatieFlysystemDropboxDropboxAdapter;
Storage::extend('dropbox', function ($app, $config) {
$client = new DropboxClient(
$config['authorization_token']
);
return new Filesystem(new DropboxAdapter($client));
});
新
use IlluminateFilesystemFilesystemAdapter;
use IlluminateSupportFacadesStorage;
use LeagueFlysystemFilesystem;
use SpatieDropboxClient as DropboxClient;
use SpatieFlysystemDropboxDropboxAdapter;
Storage::extend('dropbox', function ($app, $config) {
$adapter = new DropboxAdapter(
new DropboxClient($config['authorization_token'])
);
return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
});
在Laravel文档中,它指定了Laravel 8和9的更改。
在Laravel 8中,文件系统返回
return new Filesystem(new DropboxAdapter($client));
但是对于Laravel 9,会返回一个FilesystemAdapter。
return new FilesystemAdapter(
new Filesystem($adapter, $config),
$adapter,
$config
);
如果您使用提供商,请不要忘记更改它。