Posted inLaravel / php

laravel get env variable – How to get .env variable in blade or controller?

laravel get env variable in view, blade or controller file. Laravel – How to get .env variable in blade or controller?

laravel get env variable

We can get config variable using env() helper in Laravel. PHP Laravel Get Environment Variables Example Tutorial
Laravel Syntax:

env('VARIABLE_NAME');

Example:

env('APP_URL');

You can see bellow simple laravel example how you can get env file variable in blade or controller file.

Blade File:

@if (env('APP_ENV') == 'local')
   Local Enviroment
@endif

Controller File:
Get environment value in controller

if (env('APP_ENV') == 'local'){
    echo 'Local Enviroment';
}

get ENV variable value in Laravel Controller


So, it is very simple to get variable data from .env file like this.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype