I have a .json
file that I want to define on .env
.
How do I do that ?
my json file is on (laravel root folder)/json_google/api_key.json
.
I tried GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=/json_google/api_key.json
but doesn't work ..
Laravel has many helper functions to resolve the path. Such as base_path() in your case. You'll find all helpers here: vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
base_path(env('GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION');
However, I'd set the full path instead of a relative path. Otherwise your application has to know what it should be relative to (laravel root, or app path, ...) and take this into account, which kind of defeats the purpose of putting the file location outside your code base, as it makes it harder to move it to some place else.
As the .env file is per deployment, there is no problem with setting the full path.
You should use .env variable using constants file.
.env file
GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION=/json_google/api_key.json
Now in config/constatns.php set
return [
'STORAGE_GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION' => env("GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION", ""),
];
Fetch json file path
Config::get('constants.STORAGE_GOOGLE_SERVICE_ACCOUNT_JSON_LOCATION')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With