rkrite
397
5
Laravel

Check if Config item exists

Posted 3 months ago by rkrite

Hi,

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 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.

ie...

        $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.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.