Reputation: 3615
I have deployed my Laravel app to shared hosting and encountered a problem with env variables. The provider only allows variables with 'PHP_' prefix due to security reasons. Is it possible or would it be possible to add to Laravel to set the prefix for these variables? For now I changed the Illuminate\Foundation\helpers.php file's method env() and added:
$value = getenv($key);
if ($value === false) {
$value = getenv("PHP_" . $key);
if ($value === false)
return value($default);
}
It works, but it will be overwritten after composer update. I'm not sure if this is common approach for other hosting providers aswell, so if it would be useful to add to Laravel for the others.
Upvotes: 2
Views: 713
Reputation: 291
You can create your own helpers.php file and override the getenv() function there. As long as you load your helpers file first, then Laravel will never register it's own, since all of the helpers are wrapped with if ( ! function_exists('function_name'))
.
See this thread for some details on overriding functions in Laravel's helpers.php file.
https://laracasts.com/discuss/channels/general-discussion/override-functions-in-supporthelpersphp
Upvotes: 3