Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to configure storage in lumen 7.0

Tags:

php

laravel

lumen

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?

like image 508
Ali_Hr Avatar asked Oct 24 '25 02:10

Ali_Hr


1 Answers

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

like image 79
Yoga Cahya R. Avatar answered Oct 25 '25 15:10

Yoga Cahya R.