contains(".") ? "" : "."; // the first parameter of all enum keys are its filename [$filename, $key] = explode(".", $key, 2); // because we do not want to load the file every time use require $enums = require app_path("Enums/$filename.php"); // if the key that user provided not exists then null return $enums = Arr::get($enums, $key, null); // if enum null means that key not found throw_if($enums === null, 'Exception', "Undefined enum '{$key}'"); // if enum value is array its mean that user want to use it as collection return is_array($enums) ? collect($enums) : $enums; } }