{"record":{"id":"3bb22ed8c1c1ce45","repo":"laravel/framework","slug":"your-configuration-files-could-not-be-serialized-b","errorCode":null,"errorMessage":"Your configuration files could not be serialized because the value at \"{$key}\" is non-serializable.","messagePattern":"Your configuration files could not be serialized because the value at \"(.+?)\" is non-serializable\\.","errorType":"console","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Foundation/Console/ConfigCacheCommand.php","lineNumber":77,"sourceCode":"\n        $config = $this->getFreshConfiguration();\n\n        $configPath = $this->laravel->getCachedConfigPath();\n\n        $this->files->put(\n            $configPath, '<?php return '.var_export($config, true).';'.PHP_EOL\n        );\n\n        try {\n            require $configPath;\n        } catch (Throwable $e) {\n            $this->files->delete($configPath);\n\n            foreach (Arr::dot($config) as $key => $value) {\n                try {\n                    eval(var_export($value, true).';');\n                } catch (Throwable $e) {\n                    throw new LogicException(\"Your configuration files could not be serialized because the value at \\\"{$key}\\\" is non-serializable.\", 0, $e);\n                }\n            }\n\n            throw new LogicException('Your configuration files are not serializable.', 0, $e);\n        }\n\n        $this->components->info('Configuration cached successfully.');\n    }\n\n    /**\n     * Boot a fresh copy of the application configuration.\n     *\n     * @return array\n     */\n    protected function getFreshConfiguration()\n    {\n        $app = require $this->laravel->bootstrapPath('app.php');\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/laravel/framework/blob/deac04fbdcd7443aff45a7bc6767a6729169bba3/src/Illuminate/Foundation/Console/ConfigCacheCommand.php#L59-L95","documentation":"Thrown by ConfigCacheCommand::handle() during config:cache when the cached config file, written via var_export(), cannot be required() back (PHP throws on load). The command then iterates every dotted config key, evals its var_export representation, and reports the FIRST key whose value fails to round-trip — pinpointing the non-serializable config value (e.g., a Closure, a resource, an object without serializable form).","triggerScenarios":"Running php artisan config:cache when a config value cannot survive var_export + require. This happens when a config value is a Closure (common for services.file_DRIVER or dynamic configs), a resource, or an anonymous/object instance that var_export can't represent.","commonSituations":"Storing a Closure in config (e.g., 'redis' => fn() => ... outside allowed closures), or an object/resource; the message names the exact dotted key (e.g., 'database.connections.mysql.something') at fault.","solutions":["Inspect the config key named in the message and replace the non-serializable value (Closure/resource/object) with a plain scalar/array.","Move Closure-based logic into service providers or boot logic instead of config files.","Run config:cache only in environments where all config values are serializable.","After fixing, re-run php artisan config:cache."],"exampleFix":"// before - Closure in config (config/services.php)\n'feature' => fn () => app('settings')->all(),\n\n// after - plain serializable value or move to a provider\n'feature' => ['enabled' => env('FEATURE_ENABLED', false)],","handlingStrategy":"validation","validationCode":"// Scan config for non-serializable values before caching\nforeach (Arr::dot(app('config')->all()) as $key => $value) {\n    @eval(var_export($value, true).';');\n    if (error_get_last()) {\n        throw new LogicException('Non-serializable config at '.$key);\n    }\n}","typeGuard":"function isSerializableConfig(mixed $value): bool {\n    try {\n        eval(var_export($value, true).';');\n        return true;\n    } catch (\\Throwable) {\n        return false;\n    }\n}","tryCatchPattern":"// config:cache is a CLI command; guard in CI:\ntry {\n    \\Illuminate\\Support\\Facades\\Artisan::call('config:cache');\n} catch (\\LogicException $e) {\n    if (str_contains($e->getMessage(), 'non-serializable')) {\n        // fix the named config key, then retry\n    }\n}","preventionTips":["Never store Closures/resources/objects in config files.","Move dynamic logic into service providers or boot code.","Run config:cache in CI to catch serialization issues before deploy.","Keep config values to scalars and arrays."],"tags":["console","config-cache","serialization","deployment","config"],"analyzedSha":"deac04fbdcd7443aff45a7bc6767a6729169bba3","analyzedAt":"2026-08-06T23:23:39.652Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}