Skip to content

Instantly share code, notes, and snippets.

@peterfox
Created December 14, 2019 16:12
Show Gist options
  • Save peterfox/290a92be2a7a5c9ffd22b708202b3a12 to your computer and use it in GitHub Desktop.
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
<?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