User access to configuration file in Laravel 5 configuration files

I created my own configuration file in Laravel 5 and tried to use the settings from it in other files ( session.php , cache.php ), calling config('myconfigfile.value') , but there are no values ​​returned from my config. It seems that the configuration files have a predefined download order, and user configurations are loaded at the end or are not otherwise initialized by another reason.

How can I access my settings from laravel configuration files?

+8
php config laravel laravel-5
source share
3 answers

First you need to add the file to the configuration folder, for example: laravel \ config \ Test.php

 <?php use Illuminate\Support\Facades\Config; return [ 'name' => 'Ali Mohammed', 'age' => 26 ]; 

then you need to call config

 get('test', function(){ return Config::get('Test.name'); }); 
+10
source share

Why not just use the env() helper in every configuration file you need?

You just need to set the value in the .env file

 CUSTOM_SETTING="some value" 

and get it in every configuration file

 <?php return [ // ... 'custom_value' => env('CUSTOM_SETTING', 'some default value'), // ... ]; 

See the helper code .

+4
source share

We should also check the cache for added custom config files.

 php artisan config:cache 

Mark the link

+1
source share

All Articles