Search

Laravel Application Helper: storage_path

November 20, 2016 —John Koster

storage_path($path = '')

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 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/storage
4storage_path();
5 
6// /home/vagrant/Code/Laravel/storage/logs
7storage_path('logs');
8 
9// /home/vagrant/Code/Laravel/storage/framework/sessions
10storage_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<?php
2 
3// /home/vagrant/Code/Laravel/storage/logs/
4str_finish(storage_path('logs'), '/');

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.