Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

<?php
// config/constants.php

return [
    'SITE_NAME' => 'Site Name',
    'SITE_EMAIL' => '[email protected]',
    'ADMIN_EMAIL' => '[email protected]'
];

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?

like image 461
geoffs3310 Avatar asked Mar 01 '15 14:03

geoffs3310


1 Answers

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

config('constants.ADMIN_EMAIL')

Nice and easy ;)

like image 153
Bernig Avatar answered Oct 16 '22 08:10

Bernig