In a project recently I needed to use the filesystem features that you get in Laravel, but in the Lumen framework instead. I couldn't find a clear tutorial online to tell you have to do this, however after some research got it working using the following instructions.
First, we need to include some packages using composer; in my case I was going to be using Amazon S3 storage, so I included that.
composer require league/flysystem
After installing the league/flysystem package, you'll see a list of additional packages which it recommends you install for things such as Amazon S3, FTP etc. Install the additional packages that you think you'll use. I installed Amazon S3;
composer require league/flysystem-aws-s3-v3
Next we need to grab the configuration file from Laravel, copy the file /config/filesystems.php from Laravel and place the file into the /config folder of your Lumen project. You'll want to edit the file to provide any details required for your chosen storage, for me I amended the configuration file to pull in values from the environment file;
'disks' => [ 's3' => [ 'driver' => 's3', 'key' => env('S3_KEY'), 'secret' => env('S3_SECRET'), 'region' => env('S3_REGION'), 'bucket' => env('S3_BUCKET'), ], ],
In my env file I added the credentials for my Amazon S3 account.
S3_KEY=your_s3_key S3_SECRET=your_s3_secret S3_REGION=eu-west-1 S3_BUCKET=the_name_of_your_bucket
Edit your /bootstrap/app.php file and uncomment the following line;
$app->withFacades();
In the same file, uncomment;
$app->register(App\Providers\AppServiceProvider::class);
Finally, edit the file /providers/AppServiceProvider.php and add the following;
$this->app->singleton('filesystem', function ($app) { return $app->loadComponent('filesystems', 'Illuminate\Filesystem\FilesystemServiceProvider', 'filesystem'); });
Hopefully you should now be able to use the filesystem features in your project as you would in a Laravel project.
Comments
There are no comments, why not be the first?