Skip to content

All topics  /  Laravel

Laravel Custom Env. Variables

Laravel ·

Hi guys,

Today i am explained to the how to use in Laravel Custom Env. Variables in laravel 8 and other version in laravel. this example will help you laravel environment variables. i explained simply about how to add custom env variables in laravel.

i would like to share with you add new custom env variables laravel.

I will simple give you example of how to use Laravel Custom Env. Variables in laravel 6, laravel 7 and laravel 8 Project.The Laravel Custom Env.i will give you two examples of how to adding new env variable and how to use it with laravel 6, laravel 7 and laravel 8 application.

Here i will give you two example for laravel custom env. variables example:

Example 1: using env() helper


.env

API_TOKEN=test-demo
/**
 * The attributes that are mass assignable.
 *
 * @var array
*/
public function customeEnv()
{
    $customeEnv = env('API_TOKEN');
}

Example 2: using config() helper

config/google.php

<?php

  
return [
    'api_token' => env('GOOGLE_API_TOKEN', 'your-some-default-value'),
];
/**
 * The attributes that are mass assignable.
 *
 * @var array
*/
public function helper()
{
    $aPIToken = config('google.api_token');
}

now you can check your own.