Closed aarisfauji closed 2 years ago
same
same
same
same
Hey There,
I am facing the same error. I guess its because of Filesystem upgraded to ^3
Here is the error information I got.
Call to undefined method League\Flysystem\Filesystem::getAdapter()
UniSharp\LaravelFilemanager\LfmStorageRepository::rootPath
PROJECT_PATH\vendor\unisharp\laravel-filemanager\src\LfmStorageRepository.php
:29
public function rootPath()
{
$adapter = $this->disk->getDriver()->getAdapter();
if ($adapter instanceof CachedAdapter) {
$adapter = $adapter->getAdapter();
}
return $adapter->getPathPrefix();
}
Extra info
+-------------------------+----------------+
| Platform | WINNT |
| PHP | 8.0.16 |
| Laravel | 9.2.0 |
+-------------------------+----------------+
I just try to change function rootPath() at LfmStorageRepository.php
public function rootPath()
{
// $adapter = $this->disk->getDriver()->getAdapter();
// if ($adapter instanceof CachedAdapter) {
// $adapter = $adapter->getAdapter();
// }
// return $adapter->getPathPrefix();
return $this->path();
}
it's working, hope that not make code messed up
I just try to change function rootPath() at LfmStorageRepository.php
public function rootPath() { // $adapter = $this->disk->getDriver()->getAdapter(); // if ($adapter instanceof CachedAdapter) { // $adapter = $adapter->getAdapter(); // } // return $adapter->getPathPrefix(); return $this->path(); }
it's working, hope that not make code messed up
Hello I also had this problem, my problem was solved with your solution Thank you
Saya baru saja mencoba mengubah fungsi rootPath() di LfmStorageRepository.php
public function rootPath() { // $adapter = $this->disk->getDriver()->getAdapter(); // if ($adapter instanceof CachedAdapter) { // $adapter = $adapter->getAdapter(); // } // return $adapter->getPathPrefix(); return $this->path(); }
itu berfungsi, semoga tidak membuat kode kacau
While waiting for a fix from the UniSharp/laravel-filemanager team, I'll be following your code for a while.
I just try to change function rootPath() at LfmStorageRepository.php
public function rootPath() { // $adapter = $this->disk->getDriver()->getAdapter(); // if ($adapter instanceof CachedAdapter) { // $adapter = $adapter->getAdapter(); // } // return $adapter->getPathPrefix(); return $this->path(); }
it's working, hope that not make code messed up
and if after doing that you can't resize or crop the image, try to edit function path($type = 'storage') at vendor\unisharp\laravel-filemanager\src\LfmPath.php like this
public function path($type = 'storage')
{
........
........
} else {
// absolute: /var/www/html/project/storage/app/files/{user_slug}
// absolute on windows: C:\project\storage\app\files\{user_slug}
// return $this->storage->rootPath() . $this->path('storage');
return $this->storage->rootPath();
}
}
I don't know what i'm doing is right or not, but it's work for a while
when will the solution come?
It's because of underlying league/flysystem has been changed from v1 to v3. This dependency is not listed in the composer.json and not tested even though library relies on the details of implementation such as import of the League\Flysystem\Cached\CachedAdapter (which is not there as well in the v3)
Does anyone have a solution? I've the same problem when i create folder, upload file
@streamtw ping!
For the time being while this isn't fixed.
I use this patch composer package: https://github.com/cweagans/composer-patches With the following patch
Local file: patches/LfmStorageRepository.diff
diff --git a/src/LfmStorageRepository.php b/src/LfmStorageRepository.php
index d57e63d4..c396a042 100644
--- a/src/LfmStorageRepository.php
+++ b/src/LfmStorageRepository.php
@@ -26,13 +26,7 @@ public function __call($function_name, $arguments)
public function rootPath()
{
- $adapter = $this->disk->getDriver()->getAdapter();
-
- if ($adapter instanceof CachedAdapter) {
- $adapter = $adapter->getAdapter();
- }
-
- return $adapter->getPathPrefix();
+ return $this->disk->path('/');
}
public function move($new_lfm_path)
composer.json
"extra": {
"patches": {
"unisharp/laravel-filemanager": {
"Fix getAdapter Error": "patches/LfmStorageRepository.diff"
}
}
},
Just released v2.4.1
to fix this issue. Change the api to one that exists in Filesystem v1 ~ v3. Tested v2.4.1
with Laravel 7 and Laravel 9, both works fine.
Please upgrade to v2.4.1
.
I have tried this package in Laravel 9 with version v2.4.1 and it works fine. I will close this issue. Thank you.
Do not use laravel 9 with league filesystem 2.4
It doesn't let install v2.4.1 with Laravel 9
Still having the same issue
It appears that you're referring to a change in Laravel 9 related to the return type of Storage::disk('s3'). To address this issue without directly modifying the existing code, you can utilize Laravel macros. By adding a macro, you can extend the functionality of the AwsS3V3Adapter class and provide a new method called getAdapter().
Here's an improved comment explaining the workaround using macros:
// Workaround for Laravel 9's change in the return type of `Storage::disk('s3')`
// Add macro to the `AwsS3V3Adapter` class to provide `getClient()` and `getAdapter()` methods
AwsS3V3Adapter::macro('getClient', function () {
return $this->client;
});
AwsS3V3Adapter::macro('getAdapter', function () {
return $this;
});
// Accessing the S3 client and adapter
$client = Storage::disk('s3')->getAdapter()->getClient();
$adapter = Storage::disk('s3')->getAdapter();
By adding this macro, you are extending the AwsS3V3Adapter class and providing a new method called getClient(), which returns the existing client property. This allows you to access the underlying S3 client directly when using Storage::disk('s3') without modifying the original code.
Please note that this solution assumes you have access to the codebase and can add the macro where it will be autoloaded or registered appropriately.
This also worked for me too after upgrading to Laravel 9, AWS v3, etc. Thank you!
I've tried to install this package in Laravel 9. Then I tried to create a folder or upload an image, but the result is an error Call to undefined method League\Flysystem\Filesystem::getAdapter(). How to fix the error?