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
- in
composer.json
file, I added the following in autoload section:
"files": [
"app/helpers.php"
],
- then in app directory, I've created
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);
}
}
- I created config directory and I copied the filesystems.php from laravel in it
- then in order to register the configuration I added the following to
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?