how to configure storage in lumen 7.0

Viewed 4167

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:

  1. composer require league/flysystem
  2. in composer.json file, I added the following in autoload section:

"files": [
  "app/helpers.php"
],
  1. 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);
    }
}
  1. I created config directory and I copied the filesystems.php from laravel in it
  2. 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?

1 Answers
Related