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

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?
Link
will not work, since the route is not known by laravel...

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.

Martin Tale is right, but this is another way of accomplishing the same using Laravel's Blade:
{{ link_to('/assets/pdf/file.pdf', 'Link') }}

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')

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.

Another way, in a view:
some text
This link will go to public folder.

Related

Why doesn't my image load?

I'm building a site using laravel and I want to add a picture in one of the pages. I created an images folder that is located in \app directory and put the picture in the images folder.
So in my blade.php file that loads the site I have this code to load the image
{!! Html::image( asset('app/images/default.png'), 'Profile picture') !!}
However when I load the page I see a broken picture icon and when I inspect the element I get the message
localhost/:24 GET http://localhost:8888/app/images/default.png 404 (Not Found)
I've tried any combination that I could think of in order to make the link work but I always get a 404 error when I load the page.
Any ideas?
You should move your images folder from app to public. Do the same with all css and javascript files.
I think you don't need the app/ in the address. The assets function already know the address of your public folder.
Try it
{!! Html::image( asset('/images/default.png'), 'Profile picture') !!}

How can we link view to view without the help of controller

I am new to CodeIgniter, and I don't know whether this is possible or not. How can I link view to view without the help of controller just like PHP.
{ <a href=''>contact.php</a> }
I tried base_url(), site_url() and current_url() but this error displays:
You don't have permission to access /Buildon/User/views/contact.php on this server.
When your using codeIgniter site url or base url etc. You should send them to the controller.
CodeIgniter Doc's http://www.codeigniter.com/docs
URI Routing: http://www.codeigniter.com/user_guide/general/routing.html
URL Helper: http://www.codeigniter.com/user_guide/helpers/url_helper.html
Lets say
Contact Us
The contact_us in the base_url would be controller name.
Or Example
Example
Example
If you try to send the link to view file will not work.
Incorrect
Example
Copy this file in root of this folder parallel to index.php and then you can access it.

How to use javascript(Angular.js) with laravel get php url(asset)

I use javascript(Angular.js) with laravel
<aside data-ng-include=" {{ asset('layout/nav') }} " id="nav-container"></aside>
but is error:NotFoundHttpException load no path,
What can be read into the .php file?
Im a little confused on what you are trying to do, but it seems that you are using asset() to link a directory. I would use the laravel function link_to() instead, since it is made to generate links to paths.
Here is the link to the laravel documentation with more information on link_to() and asset():
http://laravel.com/docs/4.2/helpers#urls

Laravel Blade #include inside foreach loop

I am trying to include files on my page whose paths are stored in my db. I have tried :-
#foreach($data as $articles)
#include( $articles->path )
<br />
#endforeach
This is not working. What am I doing wrong.
I have my files in a folder called pages in view and I have added .blade.php extension as well.
You need to make sure that the path you are referencing actually exists as a file in the views folder i.e.
application/views/pages/articles/first-post.blade.php
One thing I've seen a lot of people do is add views to the home folder but not added it to the include path e.g.
application/views/home/pages/articles/first-post.blade.php
Also, it looks like you are not calling the path correctly in #include. Should be using dot notation
#include('pages.articles.first-post);
You also need to make sure you aren't trying to get a view from a bundle. You need to append the bundle name if you are, like so.
#include('bundle_name::pages.articles.first-post');

Get location of view passed into laravel view composer

Is it possible to get the location of a view that is passed into a Laravel view composer?
View::composer('*', function($view) {
// I want to find out the location of the view file here
// e.g. master.something.header
// then add this to an array
$loadedViews = View::share("loadedViews");
$loadedViews[] = $thisViewName;
});
The reason is that I want to have a variable that will be shared between views and contain an array of all the views that are loaded. Any css and js files will be located in directory structure that matches the views one.
This means I can then have a css and js view which then include the required css and js files for the views on the page. All css and js will be directly linked to a specific view.
If there is already a way to do this, or a way to get a list of loaded views, please let me know!
$view->getName() was the answer that I wanted.
$view->getPath() is the actual path to the file.

Categories