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.
#Signature
The signature of the resource_path
function is:
1function resource_path(
2 $path = ''
3);
#Example Use
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/resources
2$path = resource_path();
3
4// /Users/admin/Valet/companion/resources/lang/
5$path = resource_path('lang/');
6
7// /Users/admin/Valet/companion/resources
8// /lang/en/auth.php
9$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/'), '/'):
∎