laravel/framework · error · LogicException
Your configuration files are not serializable.
Error message
Your configuration files are not serializable.
What it means
Thrown by ConfigCacheCommand::handle() during config:cache as a fallback LogicException when the cached config file fails to require() AND no single dotted key could be isolated as the culprit (the per-key eval loop didn't itself throw). It is the generic 'your config isn't serializable' error, raised with the original load exception chained, when the more specific per-key message (error 294) couldn't be produced.
Source
Thrown at src/Illuminate/Foundation/Console/ConfigCacheCommand.php:81
$this->files->put(
$configPath, '<?php return '.var_export($config, true).';'.PHP_EOL
);
try {
require $configPath;
} catch (Throwable $e) {
$this->files->delete($configPath);
foreach (Arr::dot($config) as $key => $value) {
try {
eval(var_export($value, true).';');
} catch (Throwable $e) {
throw new LogicException("Your configuration files could not be serialized because the value at \"{$key}\" is non-serializable.", 0, $e);
}
}
throw new LogicException('Your configuration files are not serializable.', 0, $e);
}
$this->components->info('Configuration cached successfully.');
}
/**
* Boot a fresh copy of the application configuration.
*
* @return array
*/
protected function getFreshConfiguration()
{
$app = require $this->laravel->bootstrapPath('app.php');
$app->useStoragePath($this->laravel->storagePath());
$app->make(ConsoleKernelContract::class)->bootstrap();
View on GitHub (pinned to deac04fbdc)
Solutions
- Examine the chained exception ($e) for the actual load error — it reveals which value/class failed.
- Simplify config to plain serializable arrays/scalars and move dynamic logic out.
- Ensure all classes referenced by config are autoloadable at cache time.
- Clear and rebuild: php artisan config:clear then config:cache after fixing.
Example fix
// before - object in config referencing a class missing at build time 'driver' => new SomeDriver(), // after - reference by class name and instantiate in a provider 'driver' => SomeDriver::class,
Defensive patterns
Strategy: validation
Validate before calling
// Run a dry require of the var_export'd config to catch load failures
$config = app('config')->all();
$tmp = tempnam(sys_get_temp_dir(), 'cfg').'.php';
file_put_contents($tmp, '<?php return '.var_export($config, true).';');
try {
require $tmp;
} catch (\Throwable $e) {
throw new LogicException('Config not serializable: '.$e->getMessage(), 0, $e);
} finally {
@unlink($tmp);
} Type guard
function configRoundTrips(): bool {
$config = app('config')->all();
$tmp = tempnam(sys_get_temp_dir(), 'cfg').'.php';
file_put_contents($tmp, '<?php return '.var_export($config, true).';');
try { require $tmp; return true; }
catch (\Throwable) { return false; }
finally { @unlink($tmp); }
} Try / catch
try {
Artisan::call('config:cache');
} catch (\LogicException $e) {
// inspect chained $e->getPrevious() for the real load failure
report($e->getPrevious() ?? $e);
} Prevention
- Ensure all config values are plain serializable scalars/arrays.
- Make all classes referenced by config autoloadable at build time.
- Run config:cache in CI/staging before production deploy.
- Avoid referencing objects/resources in config.
When it happens
Trigger: Running config:cache; the var_export()'d config file fails to load on require, but iterating and eval'ing each dotted value individually did not reproduce the failure. This can occur with values that fail only in combination, or due to opcache/autoload state differences between eval and require.
Common situations: Complex config with interdependent objects, values that reference classes unavailable at cache-build time, or autoload/ordering issues; rare edge case of the per-key detection in error 294.
Related errors
- Your configuration files could not be serialized because the
- Callback must be a callable, callback array, or a 'Class@met
- Auth guard [{$name}] is not defined.
- Auth driver [{$config['driver']}] for guard [{$name}] is not
- Authentication user provider [{$driver}] is not defined.
AI-assisted analysis of laravel/framework@deac04fbdc (2026-08-06).
Data as JSON: /api/errors/b1c1aab5f54cb9e5.
Report an issue: GitHub.