Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save digitalkreativ/17cd94db914e6cb21b5dd9e675dd9abe to your computer and use it in GitHub Desktop.
Save digitalkreativ/17cd94db914e6cb21b5dd9e675dd9abe to your computer and use it in GitHub Desktop.
Lumen 5.2 Storage facade and s3 storage #lumen

Lumen 5.2 Storage facade

To enable the Storage facade in Lumen 5.2 you need to modify a few things.

Filesystem configuration file

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.

Change bootstrap/app.php

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.

Using AWS S3 Storage

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment