How to get env variable in controller or blade file

--

  • In this tutorial I will give you information how to get .env variable in controller or file many time we need to required of env variable in controller and blade file like if you are creating paypal integration then you have stored app id and secret key in env file. But if you haven’t any idea how to get it in controller or blade file.
  • So, let’s check how to get those variable data from .env file.

Syntax of env variable write:

env(‘VARIABLE_NAME’);

Example of env variable:

env(‘PAYPAL_CLIENT_ID’);

Example of Laravel Blade file

@if(env('APP_ENV') == 'local')
Match
@endif

Example of Laravel Controller

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

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

Read Also : How To Integrate Paypal Payment Gateway In Laravel

--

--

Websolutionstuff
Websolutionstuff

Written by Websolutionstuff

I am Laravel and PHP Developer. I have also Good Knowledge of JavaScript, jQuery, Bootstrap and REST API. Visit Website: http://websolutionstuff.com/

No responses yet