To enable the Storage
facade in Lumen 5.2 you need to modify a few things.
First of all you need to create a filesystems.php
in a config
folder.
The config
folder needs to be at the same level as your app
and bootstrap
folder. If it's not there yet just create it.
Next you can copy the default filesystems.php
of the Laravel application to that config
folder.
Once you have done that you still have to do a few changes.
Open the bootstrap/app.php
file and locate the line $app->withFacades();
. If this line is still commented out, uncomment it.
Next you have to create a binding. Add the following below the Register Container Bindings and above the comment Register Middleware.
$app->singleton('filesystem', function ($app) {
return $app->loadComponent(
'filesystems',
Illuminate\Filesystem\FilesystemServiceProvider::class,
'filesystem'
);
});
Now we still need to let Lumen know that there is a configuration file for filesystems
. To do this simply add the following line above return $app;
at the bottom of bootstrap/app.php
.
$app->configure('filesystems');
This line will tell Lumen to look for config/filesystems.php
.
If you only use local storage, you are done and you should be able to use the Storage facade. If you want to use AWS S3 Storage continue reading.
To start using AWS S3 you have to require the flysystem package with composer. Run the following command in the directory where your application composer.json
is located.
composer require league/flysystem-aws-s3-v3 ~1.0
Update the config/filesystems.php
with your own details and you are good to go.