Laravel 5: Generating Paths Relative to the Application Installation Directory With base_path

April 14, 2018 —John Koster

The base_path function can be used to retrieve the path to the directory the Laravel application is installed in. It can also be used to construct paths relative to the base path by supplying a $path.

#Signature

The signature of the base_path function is:

1function base_path(
2 $path = ''
3);

#Example Use

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// /home/vagrant/Code/Laravel/
2base_path();
3 
4// /home/vagrant/Code/Laravel/app
5base_path('app');
6 
7// /home/vagrant/Code/Laravel/public
8base_path('public');

Like the app_path function, the base_path function will not automatically add the trailing slash to the final string.

1// /home/vagrant/Code/Laravel/public/
2str_finish(base_path('public'), '/');

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.