您的配置文件不可序列化
Your configuration files are not serializable
我运行
php artisan config:cache
在我的终端上,我得到了一个 LogicException
LogicException : Your configuration files are not serializable.
at C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:68
64| require $configPath;
65| } catch (Throwable $e) {
66| $this->files->delete($configPath);
67|
68| throw new LogicException('Your configuration files are not serializable.', 0, $e);
69| }
70|
71| $this->info('Configuration cached successfully!');
72| }
Exception trace:
1 Error::("Call to undefined method Closure::__set_state()")
C:\xampp\htdocs\{PROJECT}\bootstrap\cache\config.php:241
2 require()
C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:64
Please use the argument -v to see more details.
我以前从未在 运行 此命令时遇到过此错误。请任何帮助将不胜感激。谢谢。
闭包序列化在 Laravel 和 PHP 中是不允许的。查看您的配置文件以查找您使用闭包的任何文件,并使用传统函数重写该段代码。
要找出问题的确切位置,您可以暂时从 vendor/laravel/framework/src/Illuminate/Foundation/Console/ConfigCacheCommand.php
中删除 $this->files->delete($configPath);
。通过这样做 bootstrap/cache/config.php
不会被自动删除,您可以在 config.php 文件中查找提到的行(此处为 241)。
我找到了解决类似错误的方法。
我发现我的错误与 /config/sluggable.php 文件(我安装的用于管理 slug 的包的闭包有关。
我的代码如下:
return [
reserved => function(Model $model){
return HelperController::reservedSlugs();
}
];
我做了以下操作来测试这个关闭是否是问题的原因:
return [
reserved => array()
]
那我运行php artisan optimize
。不再有问题 - 我找到了导致问题的闭包。
因此,我没有使用原来的闭包,而是执行了以下操作以获得相同的结果:
$reservedSlugs = HelperController::reservedSlugs();
return [
'reserved' => $reservedSlugs
];
我遇到了同样的问题。
我只将 toarray() 函数添加到 Setting::first() 然后它的工作。
配置仅获取数组值而不是对象数组。
config([
'global' => Settings::first()->toarray(),
]);
我的解决方案是删除 'vendor' 文件夹
然后:
- 作曲家安装
- 作曲家dump-autoload
我在 运行
时遇到了同样的问题
php artisan config:cache
它告诉我这个错误
Your configuration files are not serializable.
at vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:71
67| require $configPath;
68| } catch (Throwable $e) {
69| $this->files->delete($configPath);
70|
> 71| throw new LogicException('Your configuration files are not serializable.', 0, $e);
72| }
73|
74| $this->info('Configuration cached successfully!');
75| }
1 bootstrap\cache\config.php:671
Error::("Call to undefined method Illuminate\Validation\Rules\In::__set_state()")
2 vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:67
require()
当我调试 Project/config
目录中的所有配置时,我发现了一个由包 https://github.com/rashidlaasri/LaravelInstaller
创建的配置文件 config/installer.php
使用 Rule::in(['true', 'false'])
所以我将这段代码更改为'in:true,false'
现在工作起来很有魅力希望这会对某人有所帮助
而不是使用类似
的东西
'callback' => new App\Http\Controllers\PaymentController()
在你的任何配置文件中使用类似
的东西
'callback' => App\Http\Controllers\PaymentController::class
我运行
php artisan config:cache
在我的终端上,我得到了一个 LogicException
LogicException : Your configuration files are not serializable.
at C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:68
64| require $configPath;
65| } catch (Throwable $e) {
66| $this->files->delete($configPath);
67|
68| throw new LogicException('Your configuration files are not serializable.', 0, $e);
69| }
70|
71| $this->info('Configuration cached successfully!');
72| }
Exception trace:
1 Error::("Call to undefined method Closure::__set_state()")
C:\xampp\htdocs\{PROJECT}\bootstrap\cache\config.php:241
2 require()
C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:64
Please use the argument -v to see more details.
我以前从未在 运行 此命令时遇到过此错误。请任何帮助将不胜感激。谢谢。
闭包序列化在 Laravel 和 PHP 中是不允许的。查看您的配置文件以查找您使用闭包的任何文件,并使用传统函数重写该段代码。
要找出问题的确切位置,您可以暂时从 vendor/laravel/framework/src/Illuminate/Foundation/Console/ConfigCacheCommand.php
中删除 $this->files->delete($configPath);
。通过这样做 bootstrap/cache/config.php
不会被自动删除,您可以在 config.php 文件中查找提到的行(此处为 241)。
我找到了解决类似错误的方法。
我发现我的错误与 /config/sluggable.php 文件(我安装的用于管理 slug 的包的闭包有关。
我的代码如下:
return [
reserved => function(Model $model){
return HelperController::reservedSlugs();
}
];
我做了以下操作来测试这个关闭是否是问题的原因:
return [
reserved => array()
]
那我运行php artisan optimize
。不再有问题 - 我找到了导致问题的闭包。
因此,我没有使用原来的闭包,而是执行了以下操作以获得相同的结果:
$reservedSlugs = HelperController::reservedSlugs();
return [
'reserved' => $reservedSlugs
];
我遇到了同样的问题。 我只将 toarray() 函数添加到 Setting::first() 然后它的工作。 配置仅获取数组值而不是对象数组。
config([
'global' => Settings::first()->toarray(),
]);
我的解决方案是删除 'vendor' 文件夹 然后:
- 作曲家安装
- 作曲家dump-autoload
我在 运行
时遇到了同样的问题php artisan config:cache
它告诉我这个错误
Your configuration files are not serializable.
at vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:71
67| require $configPath;
68| } catch (Throwable $e) {
69| $this->files->delete($configPath);
70|
> 71| throw new LogicException('Your configuration files are not serializable.', 0, $e);
72| }
73|
74| $this->info('Configuration cached successfully!');
75| }
1 bootstrap\cache\config.php:671
Error::("Call to undefined method Illuminate\Validation\Rules\In::__set_state()")
2 vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:67
require()
当我调试 Project/config
目录中的所有配置时,我发现了一个由包 https://github.com/rashidlaasri/LaravelInstaller
创建的配置文件 config/installer.php
使用 Rule::in(['true', 'false'])
所以我将这段代码更改为'in:true,false'
现在工作起来很有魅力希望这会对某人有所帮助
而不是使用类似
的东西'callback' => new App\Http\Controllers\PaymentController()
在你的任何配置文件中使用类似
的东西'callback' => App\Http\Controllers\PaymentController::class