Check if Config item exists

  laravel, laravel-config

I would like to know if there is a way to check if a config item exists.

I have a case where I refer to some config items in the config/custom.php file, and others in a database table.

The concept is to make use of existing config items that exist in config/custom.php, and when they don’t exist, I pull them from my database.

$config = Config::get($configtype . '.' . $configname);

if (!$config){
    // if config not found, then get it from the database
    $configrecord = Newconfigs::where(['name' => $configname])->get()->first();
    if (!$configrecord){
        $config = false;
    } else{
        $config = $configrecord->value;

return ($config);

As you can see, doing it this way will not cater for config values of NULL of FALSE.

I would like to do something like this in my very first line to check if the config "exists" in the file…

If(Config::exists($configtype . '.' . $configname)){ } else{ //get from database }

Is there such a thing? I can’t find anything like this.

Thanks very much.

Source: Laravel

Leave a Reply