Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Laravel .env variables in blade

Tags:

php

laravel

I am trying to get some API keys which I have stored in my .env file to use in the blade javascript. I have added two keys like:

APP_ENV=local APP_KEY=//// APP_DEBUG=true APP_LOG_LEVEL=debug APP_URL=http://localhost APP_GOOGLE_MAPS=//// APP_OVERHEID_IO=//// 

In blade I need to use the Google Maps API and OverheidIO API key. I have tried getting one of the default .env variables just in case I have formatted the custom .env variables wrong.:

{{ env('APP.ENV') }} // nothing {{ env('APP_ENV') }} // nothing {{ env('APP_ENV'), 'test' }} // returns 'test'  

Could someone help me call the google maps api and overheidio api key in the blade?

like image 982
Anna Jeanine Avatar asked Mar 27 '17 08:03

Anna Jeanine


People also ask

Can I use variables in .env file?

The . env file contains the individual user environment variables that override the variables set in the /etc/environment file. You can customize your environment variables as desired by modifying your . env file.


2 Answers

Five most important commands if your Laravel is not working as expected after some modifications in .env or database folder or because of any other modifications. Here is full explanation: https://www.youtube.com/watch?v=Q1ynDMC8UGg

php artisan config:clear php artisan cache:clear composer dump-autoload php artisan view:clear php artisan route:clear 
like image 73
Abhay Maurya Avatar answered Oct 03 '22 19:10

Abhay Maurya


I have it implemented in the following way:

@if (env('APP_ENV')!='Production') Enviroment Test @endif 

My recommendation is to execute the following command: composer self-update

like image 43
Armando Cordova Avatar answered Oct 03 '22 17:10

Armando Cordova