How to Get env Data in Laravel

AuthorSumit Dey Sarkar

Pubish Date22 Mar 2023

categoryLaravel

In this tutorial we will learn how to get env data in Laravel.

 

How to get env data in Laravel

In Laravel, you can retrieve environment variables using the env function.

Here's an example of how to retrieve an environment variable named APP_NAME:

$envValue = env('APP_NAME');

 

This will retrieve the value of the APP_NAME environment variable from your .env file. If the variable is not set in the .env file, it will return null.

You can also provide a default value as the second argument to the env function:

$envValue = env('APP_NAME', 'My Default Value');

This will retrieve the value of the APP_NAME environment variable if it is set in the .env file. If it is not set, it will return the default value of My Default Value.

Comments 0

Leave a comment