Search

Laravel Application Helper: base_path

November 20, 2016 —John Koster

base_path($path = '')

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.

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

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

1<?php
2 
3// /home/vagrant/Code/Laravel/public/
4str_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.