How To Get env Variable In Controller Or Blade File

Websolutionstuff | Jul-26-2020 | Categories : Laravel

In this tutorial, I will give you information on how to get the .env variable in the controller or file. Many times we need to require an environment variable in the controller and blade file like if you are creating PayPal integration then you have stored the app id and secret key in the env file or any other details about hosting, web hosting, credit card, and payment details. But if you haven't any idea how to get it in the controller or blade file.

So, let's check how to get those variable data from the .env file.

Syntax:

env('VARIABLE_NAME');

 

 

Example:  

env('PAYPAL_CLIENT_ID');

 

Blade file

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

Controller

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

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

 

Recommended Post
Featured Post
Autocomplete Search from Database in Laravel 11
Autocomplete Search from Datab...

Hello, laravel web developers! In this article, we'll see how to autocomplete a search from a database in larav...

Read More

Jun-24-2024

Dropzone Image Upload Tutorial In Laravel 6/7
Dropzone Image Upload Tutorial...

In this article, we will see dropzone image upload in laravel 6/7. To upload images and files we will use dropzone....

Read More

Sep-21-2020

How To Store Backup On Dropbox In Laravel 9
How To Store Backup On Dropbox...

In this article, we will see how to store the backup on dropbox in laravel 9. Here, we will learn to store database...

Read More

Jan-16-2023

Laravel 10: New Features And Release Date
Laravel 10: New Features And R...

In our ever-changing digital landscape, staying ahead of the competition is essential. And that's precisely what we&...

Read More

Jan-11-2023