April 14, 2018 —John Koster
The storage_path
will return the path to the storage
directory. It can also be used to construct paths relative to the storage
directory if a $path
is supplied.
The signature of the storage_path
function is:
1function storage_path(2 $path = ''3);
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/storage2storage_path();3 4// /home/vagrant/Code/Laravel/storage/logs5storage_path('logs');6 7// /home/vagrant/Code/Laravel/storage/framework/sessions8storage_path('framework/sessions');
The storage_path
does not automatically add the trailing slash /
character to the final string. storage_path
's return value can be passed into the str_finish
function to achieve the same affect:
1// /home/vagrant/Code/Laravel/storage/logs/2str_finish(storage_path('logs'), '/');
∎
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.