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

Paj4love's avatar

Download a file in Laravel using a URL stored in the database from external resource

hi, i can't download using this

	<div class="mt-5 col-md-6">
    @foreach ($orders->orderitems as $item)
    		<a href="{{ url('/download'.$item->licenses->download_link) }}" class="btn btn-primary">Download Your Beat Now!</a>
    @endforeach
    </div>

The download url that is stored in the database looks like this: https://drive.google.com/file/d/1l7uPUV1TULVvXXb_rERWAZLS-VDI9NOh/view?usp=sharing

So when i click on download button, it takes me to this url instead of downloading the file: http://127.0.0.1:8000/downloadhttps://drive.google.com/u/0/uc?id=1l7uPUV1TULVvXXb_rERWAZLS-VDI9NOh&export=download

but if i copy the same file i stored in my database and peast it in a browser it start downloading. My Controller

public function download(Request $request, $file)
{
    //return response()->download(public_path('assets/uploads/licenses/audio/'.$file));
    return response()->download();
}

Please Somebody Should Help

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

You do not need the url helper since the download link in the database is absolute

<a href="{{ $item->licenses->download_link }}" class="btn btn-primary">Download Your Beat Now!</a>

Be aware that you have no control over this link - it can be shared. If you need to control who can access the link, then you will need to pass through your application to authenticate/authorize the user.

1 like

Please or to participate in this conversation.