By John Koster
public_path($path = '')
The public_path
will return the path to the public
directory. It can also be used to construct paths relative to the public
directory if a $path
is supplied.
The following examples will assume that the Laravel application is installed in the
/home/vagrant/Code/Laravel/
directory. The resulting path will appear above the function calls as a comment.
1<?php
2
3// /home/vagrant/Code/Laravel/public
4public_path();
5
6// /home/vagrant/Code/Laravel/public/js
7public_path('js');
The public_path
does not automatically add the trailing slash /
character to the final string. public_path
's return value can be passed into the str_finish
function to achieve the same affect:
1<?php
2
3// /home/vagrant/Code/Laravel/public/js/
4str_finish(public_path('js'), '/');
∎