2021-03-15 12:26:39 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Helpers;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-03-15 12:26:39 -07:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
|
|
|
|
class StorageHelper
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
public static function downloader($filename, $disk = 'default')
|
|
|
|
{
|
|
|
|
if ($disk == 'default') {
|
2021-03-15 12:26:39 -07:00
|
|
|
$disk = config('filesystems.default');
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
switch (config("filesystems.disks.$disk.driver")) {
|
2021-03-15 12:26:39 -07:00
|
|
|
case 'local':
|
|
|
|
return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?!
|
|
|
|
|
|
|
|
case 's3':
|
|
|
|
return redirect()->away(Storage::disk($disk)->temporaryUrl($filename, now()->addMinutes(5))); //works for private or public, I guess?
|
|
|
|
|
|
|
|
default:
|
|
|
|
return Storage::disk($disk)->download($filename);
|
|
|
|
}
|
|
|
|
}
|
2021-06-10 13:15:52 -07:00
|
|
|
}
|