How to Get All env Variables in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

Hello Friends,

This detailed guide will cover laravel get all env variables. This post will give you a simple example of how to get all env variables in laravel. This post will give you a simple example of get all environment variables laravel. This article will give you a simple example of laravel get all environment variables example.

You can use these tips with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 versions.

If you want to access all env variables then laravel provides $_ENV variable to get all environment variables. so let's see the simple example the below:

Example:

app/Http/Controllers/DemoController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

/* Getting All Env Variables */

$allEnvVar = $_ENV;

/* Getting All Env Variables */

$dbName = $_ENV['DB_DATABASE'];

dd($allEnvVar, $dbName);

}

}

Output:

I hope it can help you...

Tags :
Shares