April 14, 2018 —John Koster
The resource_path
helper function can be used to resolve the path to the resource directory, or to sub-directory or file contained within the resources directory.
The signature of the resource_path
function is:
1function resource_path(2 $path = ''3);
The following example assume that the Laravel application's root directory is located at /Users/admin/Valet/companion
. The resource_path
helper function will return the full path.
This example demonstrates how to resolve various resource paths, the results of the function call will appear of the function call as a comment:
1// /Users/admin/Valet/companion/resources2$path = resource_path();3 4// /Users/admin/Valet/companion/resources/lang/5$path = resource_path('lang/');6 7// /Users/admin/Valet/companion/resources8// /lang/en/auth.php9$path = resource_path('lang/en/auth.php');
The resource_path
helper function does not append the trailing forward slash; the trailing forward slash can be added by calling the str_finish
function after calling the resource_path
function; both function calls would return the same result:
1// Get a resource_path with the trailing forward slash.2$path = str_finish(resource_path('lang'), '/'):3 4$path = str_finish(resource_path('lang/'), '/'):
∎
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.