In this tutorial you will learn about the Laravel Custom Env. Variables and its application with practical example.
In this tutorial, I’ll show you how to create Custom Env. Variables in laravel 8. In this example we will create custom laravel environment variable.
Laravel Custom Env. Variables
In this step by step laravel custom environment variable tutorial, we will learn to add custom env. variable in our laravel application.
using env() helper
.env
1 |
API_TOKEN=test-demo |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * The attributes that are mass assignable. * * @var array */ public function customeEnv() { $customeEnv = env('API_TOKEN'); } |
using config() helper
config/google.php
1 2 3 4 5 6 7 |
<?php return [ 'api_token' => env('GOOGLE_API_TOKEN', 'your-some-default-value'), ]; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
/** * The attributes that are mass assignable. * * @var array */ public function helper() { $aPIToken = config('google.api_token'); } |
wer