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
Laravel 8 One To Many Polymorphic Relationship
Laravel 8 One To Many Polymorp...

In this tutorial we will learn about laravel 8 one to many polymorphic relationship. A one-to-many polymorphic rela...

Read More

Nov-19-2021

Mail: Laravel 11 Send Email using Queue
Mail: Laravel 11 Send Email us...

In this guide, we'll see how to send email using a queue in laravel 11. Here we'll see the concept of queue...

Read More

Apr-12-2024

Razorpay Payment Gateway Integration in Laravel 10 and VueJS 3
Razorpay Payment Gateway Integ...

In the rapidly advancing world of technology, the combination of Laravel 10 and VueJS 3 is unparalleled and exceptionall...

Read More

Aug-30-2023

Laravel 8 Highcharts Example Tutorial
Laravel 8 Highcharts Example T...

Hello guys, In this tutorial we will see laravel 8 highcharts example tutorial. you will learn how to imple...

Read More

Jul-02-2021