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
How To Validate 10 Digit Mobile Number Using Regular Expression
How To Validate 10 Digit Mobil...

In This small tutorial, I will explain to you how to validate a 10-digit mobile number using regular expressions in...

Read More

Jun-15-2020

How to Create ZIP Archive File in Laravel 11 Example
How to Create ZIP Archive File...

Hello, laravel web developers! In this article, we'll see how to create a zip archive file in laravel 11. You can cr...

Read More

Jul-17-2024

How To Check RAM And CPU Usage In Laravel
How To Check RAM And CPU Usage...

In this tutorial, I will show you how to check RAM and CPU usage in laravel in ubuntu OS. Many times we requir...

Read More

Jul-29-2020

How To Create Dynamic Pie Chart In Laravel 9
How To Create Dynamic Pie Char...

In this article, we will see how to create a dynamic pie chart in laravel 9. Pie charts are used to repre...

Read More

Mar-20-2022