Reputation: 4675
In laravel we can use storage Facade in order to save and read files, but in lumen 7.0 there is no filesystem config available at start.
what I did so far:
composer require league/flysystem
composer.json
file, I added the following in autoload section:
"files": [
"app/helpers.php"
],
helpers.php
and added the following into it:if (! function_exists('public_path')) {
/**
* Get the path to the public folder.
*
* @param string $path
* @return string
*/
function public_path($path = '')
{
return app()->make('path.public').($path ? DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR) : $path);
}
}
if (! function_exists('storage_path')) {
/**
* Get the path to the storage folder.
*
* @param string $path
* @return string
*/
function storage_path($path = '')
{
return app('path.storage').($path ? DIRECTORY_SEPARATOR.$path : $path);
}
}
bootstrap/app.php
:$app->singleton('filesystem', function ($app) {
return $app->loadComponent('filesystems', 'Illuminate\Filesystem\FilesystemServiceProvider', 'filesystem');
});
$app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');
$app->instance('path.public', app()->basePath() . DIRECTORY_SEPARATOR . 'public');
After doing all changes that I made to lumen, when I try to use Storage Facade for example:
Storage::file($dir);
it will throw an error that says:
Class 'League\Flysystem\Adapter\Local' not found
What is wrong with my configuration?
Upvotes: 4
Views: 6569
Reputation: 125
I think you used flysystem version 2.0
I had same issue, and then used v1.1 and it worked.
So run composer require --dev league/flysystem=^1.1
source : https://github.com/barryvdh/laravel-ide-helper/issues/1105
Upvotes: 4