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.

Also Read This πŸ‘‰   Class HTML not found laravel

Blade File:

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

Free Live Chat for Any Issue

Controller File:
Get environment value in controller

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

get ENV variable value in Laravel Controller

<?php $hostname = env("IMAP_HOSTNAME_TEST", "localhost"); ?>

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

5/5 - (4 votes)