DEV Community


How to get env variable in controller or blade file

websolutionstuff profile image Websolutionstuff Originally published at ・1 min read

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.

Read Also : Laravel AJAX CRUD example

Syntax of env variable write:


Example of env variable:


Example of Laravel Blade file

@if(env('APP_ENV') == 'local')
Enter fullscreen mode Exit fullscreen mode

Example of Laravel Controller

if(env('APP_ENV') == 'local')
  echo 'Match';
Enter fullscreen mode Exit fullscreen mode

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

Read Also : How To Integrate Paypal Payment Gateway In Laravel

Discussion (0)

Editor guide