Laravel Add Custom Configuration File Example
Now, let's see article of laravel add custom configuration file. This article will give you simple example of laravel custom config file. we will help you to give example of laravel custom configuration file. you can see how to create custom config file in laravel. Let's get started with create your own config file laravel.
you can easily create custom configuration file in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.
in this example, we will create google.php config file and set api key on there. then we will simply get value using config() helper. let's see example.
Example
now first add your new variable on env file as like bellow:
.env
...
GOOGLE_API_TOKEN=xxxxxxxx
config/google.php
<?php
return [
'api_token' => env('GOOGLE_API_TOKEN', 'your-some-default-value'),
];
Use it:
Route::get('helper', function(){
$googleAPIToken = config('google.api_token');
dd($googleAPIToken);
});
Output:
xxxxxxxx
now you can check your own.
i hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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 use Laravel Model Observers?
- Laravel 8 Clear Cache of Route, View, Config Command Example
- How to Use Environment Variable in Angular?
- Laravel Deployment on Cloudways with Envoyer
- How to Set Config Value Dynamically in Laravel?
- How to Get Config Variable Value in Laravel?
- How to Configure Git Username and Email?
- Laravel Clear Cache from Route, View, Config Example
- How to Send Mail using Gmail SMTP in Laravel?