Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel routing: How to create a link to a PDF file

I need to generate PDF documents and have them send by email as well as make them reachable by a link. Sending by email is OK, but I have no idea how to create the link.

Since I use Laravel 4, all links are going through routes.php. So how do I create a link to a file at a given directory?

<a href="http://my.domain.org/assets/pdf/file.pdf">Link</a> 

will not work, since the route is not known by laravel...

like image 620
user2746374 Avatar asked Sep 05 '13 15:09

user2746374


2 Answers

To generate a link to a physical file or directory, that you don't want to run through Laravel's application (e.g. through index.php), use URL::asset().

URL::asset('assets/pdf/file.pdf');

This assumes you've created a physical PDF file on your server that you want to link to. If your PDF file is dynamic and generated/retrieved through your Laravel application, you should use URL::to(), URL::route(), or similar.

like image 107
Aken Roberts Avatar answered Sep 18 '22 17:09

Aken Roberts


Martin Tale is right, but this is another way of accomplishing the same using Laravel's Blade:

{{ link_to('/assets/pdf/file.pdf', 'Link') }} 
like image 33
Antonio Carlos Ribeiro Avatar answered Sep 20 '22 17:09

Antonio Carlos Ribeiro