geoffs3310 geoffs3310 - 9 months ago 82
PHP Question

Adding a new config file in Laravel 5 not working

I want a new config file in my Laravel 5 app to store all my constants in. After looking around the net I found the recommended solution seems to be to create a new config file that returns an array of key value pairs and then use that. So I created the following file:

// config/constants.php

return [
'SITE_NAME' => 'Site Name',
'SITE_EMAIL' => '',

Then in one of my controllers I try to access one of these values like so:

echo Config::get('constants.ADMIN_EMAIL');

I just get the following error:

FatalErrorException in WelcomeController.php line 46:
Class 'App\Http\Controllers\Config' not found

Do I have to do something else to get it to work?


In Laravel 5, to avoid this kind of headache, you can use the config helper function to get a config item, like this :


Nice and easy ;)