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 Create Custom Login and Registration in Laravel 10
How to Create Custom Login and...

In the ever-evolving landscape of web development, crafting a tailor-made user authentication system stands as a pivotal...

Read More

Aug-25-2023

Laravel 9 Socialite Login with Google Account
Laravel 9 Socialite Login with...

In this article, we will see laravel 9 socialite login with a google account. This post gives you an example of a larave...

Read More

Apr-15-2022

How To Generate QR Code In Angular 13
How To Generate QR Code In Ang...

In this article, we will see how to generate QR code in angular 13. In this example, we will use the angularx-qrcod...

Read More

Jun-09-2022

How To Integrate Swagger In laravel 10
How To Integrate Swagger In la...

In the dynamic realm of modern web development, ensuring that APIs are well-documented, easy to comprehend, and seamless...

Read More

Aug-18-2023