10

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...

Martin Tale
  • 877
  • 1
  • 6
  • 18
user2746374
  • 101
  • 1
  • 1
  • 3
  • I have answer for you [here](http://stackoverflow.com/questions/18412680/jquery-mobile-links-and-radio-buttons-in-accordion-not-working/18412960#18412960) this how do this – ShapCyber Sep 05 '13 at 15:47
  • If you put your PDF file in your public directory you can create a direct link, did you tried it? – Rubens Mariuzzo Sep 05 '13 at 15:50

5 Answers5

10

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.

Aken Roberts
  • 13,012
  • 3
  • 34
  • 40
5

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

{{ link_to('/assets/pdf/file.pdf', 'Link') }} 
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
2

Create that PDF somewhere in public directory and then create a link to that file like this:

URL::to('path/to/public/directory/file.pdf')
Martin Tale
  • 877
  • 1
  • 6
  • 18
0

if you are using laravel 4's MAIL feature you can add this to it

$message->attach($pathToFile);

but the .pdf in your public directory under a pdf folder and that will make it:

$message->attach('pdf/mypdffile.pdf');

the same can be for a link which you can add to the email

{{ URL::to('pdf/mypdffile.pdf') }}

You shouldn't need a route to create a link it can be done by blade.

Lynx
  • 1,462
  • 5
  • 32
  • 59
0

Another way, in a view:

<a href="{{ asset('/your_pdf_file.pdf') }}">some text</a>

This link will go to public folder.

entoniperez
  • 544
  • 5
  • 14