Determining If a Configuration Group Exists

Problem

You want to see if a configuration group exists.

You know Laravel organizes the configuration into groups and these groups are implemented as individual config files. For instance the app/config/database.php contains configuration for the database group.

You want to see if the group even exists.

Solution

Use Config::hasGroup().

if (Config::hasGroup('session'))
{
    echo "I have a config/session.php file!";
}

Discussion

This only works for groups existing in the production environment.

In other words, if your environment is local and you have a app/config/local/shoes.php file, but no top level app/config/shoes.php then the Config::hasGroup("shoes") statement will return false.

comments powered by Disqus