file download for private files

I have a FileUpload field in my form. It uploads to the local driver because the uploaded files are buying invoices which should only be downloadable and viewable by logged in users. The ->downloadable() function returns a 404 not found. So I have made a controller to return the download from Storage. This function does work. Is there a way to replace the downloadable() url to this custom url so it downloads via the controller instead? Or is there another better way to handle these private files?
No description
No description
1 Reply
toeknee
toeknee15mo ago
No that should suffice just make sure it's a one time temporary url Here is an example what I did:
Route::get('tmp/{path}', function (string $path) {
return Storage::disk('private_files')
->download(Crypt::decryptString($path));
})->name('tmp');
Route::get('tmp/{path}', function (string $path) {
return Storage::disk('private_files')
->download(Crypt::decryptString($path));
})->name('tmp');
Then I format the URL to be an encrypted string of the path. You could chuck an array into the crypt and then test the path and then a time so you only allow it for X time and else return expired
Want results from more Discord servers?
Add your server