Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dogma's avatar
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..

0 likes
2 replies
martinbean's avatar

@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?

dogma's avatar
Level 1

@martinbean Because I refer to it via a qr code from another physical source too. And I wanted to have a central route, from where the file is downloadable.

Please or to participate in this conversation.