12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace App\Providers;
- use Illuminate\Support\ServiceProvider;
- use Illuminate\Support\Facades\Storage;
- use League\Flysystem\Filesystem;
- use League\Flysystem\Local\LocalFilesystemAdapter;
- class FileSystemServiceProvider extends ServiceProvider
- {
- public function boot()
- {
- Storage::extend('s3', function ($app, $config) {
- $adapter = new \League\Flysystem\AwsS3V3\AwsS3V3Adapter(
- new \Aws\S3\S3Client($config),
- $config['bucket'],
- $config['root'] ?? ''
- );
- return new class($adapter, $config) extends Filesystem {
- protected $config;
- public function __construct($adapter, $config)
- {
- parent::__construct($adapter);
- $this->config = $config;
- }
- public function url($path)
- {
- return "/api/download?filename={$path}&bucket={$this->config['bucket']}";
- }
- };
- });
- }
- }
|