@dogma Why are you creating a controller to download the file, if the file is just in your public disk and publicly accessible any way?
Jun 7, 2024
2
Level 1
Asset vs public path
Hey,
I stumbled across the following issue:
Customers have to download a pdf file from the website. The pdf file is in the public folder: pdf/manual.pdf
My route file:
Route::get('/manual', [StoreController::class, 'fDownloadManual'])->name('manual');
My Controller function
public function fDownloadManual () {
// v.1 return response()->download(asset('pdf/insole_manual.pdf'));
v.2 return response()->download(public_path('pdf/insole_manual.pdf');
}
v.1 isn't working, with the error:
Symfony \ Component \ HttpFoundation \ File \ Exception \ FileNotFoundException
PHP 8.1.20
9.52.16
The file "http://127.0.0.1:8000/pdf/insole_manual.pdf" does not exist
My app.php file:
'asset_url' => env('ASSET_URL', null),
While ASSET_URL isn't set in my .env.
v.2 is working just fine.
Is there any reason why I can't use asset in this case?
I thought using it inside a controller shouldn't be a problem..
Please or to participate in this conversation.