Share this:

Today, we are going to learn Laravel 9 Get env Variable in Blade File Example. This tutorial will cover on how to get .env variable in blade file with example.

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.

Steps for Laravel 9 Get env Variable in Blade File Example:

  • Step 1: Installing fresh new laravel 9 application
  • Step 2: Set environment variable
  • Step 3: Get env Variable in Laravel Blade
    • Example 1
    • Example 2
    • Example 3
    • Example 4
  • Step 4: Conclusion

Also Read: How to Use Inner Join In Laravel 9

Step 1: Installing fresh new laravel 9 application

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

Step 2: Set environment variable

APP_NAME=LaravelTuts
APP_ENV=local
APP_KEY=base64:****
APP_DEBUG=true
APP_URL=http://localhost

Also Read: Laravel 9 User Roles and Permissions Tutorial Example

Step 3: Get env Variable in Laravel Blade

Let see all the examples on how to get .env variable in laravel blade files.

Example 1:

In this step, we will get simply environment variable and print it in blade file.

<p>{{ env('APP_NAME') }}</p>

Output:

"LaravelTuts"

Also Read: Laravel 9 Vue JS Form Validation Example

Example 2:

In this step, we will check environment variable.

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

Output:

Local

Example 3:

In this step, we will get simply environment variable using config function.

{{ config('app.name') }}

Output:

LaravelTuts

Also Read: Laravel Vue 3 File Uploading with Progress Bar using Vite Example

Example 4:

In this step, we will see how to get environment variable in script tag.

<script>
var name = '{{ env('APP_NAME') }}';
console.log(name);
</script>

Output:

LaravelTuts

Step 4: Conclusion

Today, We had learn Laravel 9 Get env Variable in Blade File Example. Hope this tutorial helped you with learning Laravel 9. If you have any question you can ask us at comment section below. If you like the tutorial please subscribe our YouTube Channel and follow us on social network Facebook and Instagram.

Also Read: Laravel 9 Livewire Multi Step Form Wizard Tutorial

Share this:

Categorized in: