我想知道是否有办法检查配置项是否存在。
我有一个案例,我在 config/custom.php 文件中引用了一些配置项,而在数据库表中引用了其他配置项。
这个概念是利用 config/custom.php 中存在的现有配置项,当它们不存在时,我从我的数据库中提取它们。
$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);
如您所见,这样做不会满足 FALSE 的 NULL 配置值。
我想在我的第一行做这样的事情来检查文件中的配置是否“存在”......
If(Config::exists($configtype . '.' . $configname)){ } else{ //get from database }
有这样的事吗?