aesterisk_
aesterisk_

Reputation: 359

Use Laravel's Config class inside of app.php

I've created a single, custom config file (config/myconfig.php for example's sake) so anyone can easily change options quickly in one place to work in their particular environment with configurable options.

I've had success getting these config keys working in some files (my controllers and even in database.php). However, it seems like I cannot use the Config class in app.php. For example I'd like to set 'debug' => Config::get('myconfig.debug_enabled') but I keep getting an error: Class 'Config' not found.

Maybe I'm just missing something or just have the wrong approach. Any direction would be greatly appreciated.

Cheers.

Upvotes: 3

Views: 9126

Answers (2)

kfriend
kfriend

Reputation: 2614

In the app.php config, the facade aliases have not been loaded yet (they're contained in the app.php file). If you add use Illuminate\Support\Facades\Config; to the top (after <?php), you'll be able to use Config::get().

Upvotes: 6

Antonio Carlos Ribeiro
Antonio Carlos Ribeiro

Reputation: 87719

Laravel published a global app() function, which gives you access to the IoC container, so you can do:

app()->make('config')->get('database.default')

This one just worked for me inside app.php.

Upvotes: 2

Related Questions