It seems like the environment variables are not being loaded properly on the server. Here are a few steps you can take to troubleshoot and fix the issue:
Check the .env file: Make sure that the .env file exists in the root directory of your Laravel project on the server. Verify that the necessary environment variables (e.g., APP_NAME, STRIPE_KEY) are defined correctly in the .env file.
Clear the configuration cache: Run the following command on the server to clear the configuration cache:
php artisan config:clear
This will ensure that any changes made to the .env file are reflected in the application.
Restart the server: If the above steps don't work, try restarting the server to ensure that the changes take effect.
If the issue persists, it's possible that the server's environment is not properly configured. You may need to consult with your server administrator or hosting provider for further assistance.
Additionally, make sure that you are using the correct syntax to access the environment variables in your blade templates. The syntax you provided ({{ env('APP_NAME') }}) is correct, but double-check that the variable names match exactly with what is defined in the .env file.
You should not be using environment variables anywhere in your code except in config files, because the .env file is not loaded after config is cached.
Thanks @tykus I wasn't aware of this as I'm quite new to laravel :)
php config:clear has solved the problem immediately but I would also prefer to move these into config files as you suggest...
So for example, where I need to access an .env constant like STRIPE_KEY from blade templates, should I edit config/view.php and add something like:
'stripe_key' => env('STRIPE_KEY')
@Lozza Usually stripe and other services keys are located in the config/services.php config file. The key will be dot-syntax beginning with the filename followed by the path to the value, e.g. services.stripe.key for the following: