Created
December 14, 2019 16:12
-
-
Save peterfox/290a92be2a7a5c9ffd22b708202b3a12 to your computer and use it in GitHub Desktop.
A Helper for use with Laravel to make configs using path names a lot easier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// | |
// Say the project is stored in the path /var/html then it could be used like so: | |
// | |
// dynamic_base_path('@storage/app/somefile.txt'); // returns /var/html/storage/ | |
// | |
// dynamic_base_path('/etc/somefile.txt'); // returns /etc/somefile.txt | |
// | |
// Use this in your config files when you want relative paths for your local | |
// environment but fixed for your production etc. | |
// | |
function dynamic_base_path($path) { | |
if (Str::startsWith($path, '@')) { | |
return base_path(substr($path, 1)); | |
} | |
return $path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment