Laravel Get env Variable in Blade File Example


Share:
 | Published By: Admin | Published On: Aug 01, 2022 | Category: Laravel 9

Hello Friends,

This article will provide some of the most important example Laravel Get env Variable in blade File Example. this example will help you laravel get env variable in blade. I’m going to show you about how to access env variable in laravel blade. In this article, we will implement a how to get env variable in laravel blade. you will do the following things for laravel get env variable in view.

You can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 version.

Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
Set environment variable
APP_NAME=Mywebtuts
APP_ENV=local
APP_KEY=base64:****
APP_DEBUG=true
APP_URL=http://localhost
Get env Variable in Laravel Blade

This Step We Will Get Simply environment Variable Print in Blade file.

Example 1 :
<p>{{ env('APP_NAME') }}</p>
Output :
"Mywebtuts"
Example 2 :

In This Step We Will Chack environment Variable.

@if(env('APP_ENV') == 'local')
       Match
@endif
Output :
Match
Example 3 :

In this Step We Will Get Simply environment Variable using config function.

{{ config('app.name') }}
Output :
Mywebtuts
Example 4 :

In this Step We Will see how to get environment Variable in script teg.

<script>

var name = '{{ env('APP_NAME') }}';

console.log(name);

</script>
Output :
Mywebtuts

now it works...

I hope it can help you...

Share: