laryn's picture

What is the best way (via code, e.g. in a custom module) to check if a configuration file already exists?

Accepted answer

@Herb suggests (on Zulip) something like this:

$config = config('mymodule.settings');
if (!$config->isNew()) {

If the config has never existed before then it'll exist only as an object and have the isNew flag. Otherwise you know it existed previously.

Comments

@Herb suggests (on Zulip) something like this:

$config = config('mymodule.settings');
if (!$config->isNew()) {

If the config has never existed before then it'll exist only as an object and have the isNew flag. Otherwise you know it existed previously.

You could also use:

There's probably lots of other ways too...