How to Get All env Variables in 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 and laravel 10 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...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check Running Laravel App Environment?
- How to Get Environment Variable in Laravel React JS?
- Laravel Collection Get First and Last Item Example
- How to Get Last Month Data in Laravel?
- Laravel Google Autocomplete Address Example
- Laravel File Manager Tutorial Step by Step
- Laravel Custom Email Verification System Example
- How to Add Custom env Variables in Laravel?
- How to Compare Two Dates in Laravel Carbon?
- Laravel Deployment on Cloudways with Envoyer
- How to Enable Rewrite Mode for Apache in Ubuntu?
- How to Set URL without Http of Other Site in Laravel?
- Laravel Create JSON File & Download From Text Example