// Step 1: Install package
composer require league/flysystem-aws-s3-v3
// Step 2: Add this code in config/filesystems.php
'spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'region' => env('DO_SPACES_REGION'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'bucket' => env('DO_SPACES_BUCKET'),
'url' => env('DO_SPACES_URL'),
],
// Step 3: Add this code in .env file
DO_SPACES_KEY=your_key
DO_SPACES_SECRET=your_secret
DO_SPACES_REGION=your_region
DO_SPACES_ENDPOINT=https://your_region.digitaloceanspaces.com
DO_SPACES_BUCKET=your_bucket
DO_SPACES_URL=https://your_bucket.your_region.digitaloceanspaces.com
// Step 4: Add this code in your controller
use Illuminate\Support\Facades\Storage;
public function download($file)
{
$path = Storage::disk('spaces')->getDriver()->getAdapter()->getClient()->getObjectUrl(env('DO_SPACES_BUCKET'), $file);
return redirect($path);
}
// Step 5: Add this code in your route
Route::get('/download/{file}', [YourController::class, 'download'])->name('download');
// Step 6: Add this code in your view
<a href="{{ route('download', $file) }}">Download</a>
I tried to explain in detail, I hope it helps :)