php artisan config 上的 Laravel 5:清除生成的 Closure::__set_state() 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31154313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:17:28  来源:igfitidea点击:

Laravel 5 on php artisan config:clear generated Closure::__set_state() error

phplaravel-5

提问by Tarunn

My code in on production and I ran

我的代码在生产中,我跑了

php artisan config:clear

After that, my code was not running. The index pages and all other pages went white screen and gave 500 internal server error in firebug. When I tried to run

在那之后,我的代码没有运行。索引页面和所有其他页面都出现白屏,并在 firebug 中出现 500 内部服务器错误。当我试图跑

php artisan

it gave me error as

它给了我错误

PHP Fatal error:  Call to undefined method Closure::__set_state() in /var/www/live/vendor/config.php on line 56

My code is in production!! /vendor/config.php file was not present before, what happened with that code?? Have you faced any such error? I had given all permissions to storage/ folder and vendor/. Any help/guide would be much appreciated.

我的代码正在生产中!!/vendor/config.php 文件以前不存在,那个代码发生了什么?你遇到过这样的错误吗?我已授予存储/文件夹和供应商/的所有权限。任何帮助/指南将不胜感激。

回答by geckob

I had similar issues when I ran php artisan config:cache. Apparently, it is an issue when the application is trying to load cached configuration files that have closures in it. It won't be fixed in Laravel since it is a bad practice to have closures in config files. Refer this Github issue

我在跑步时遇到了类似的问题php artisan config:cache。显然,当应用程序尝试加载包含闭包的缓存配置文件时,这是一个问题。它不会在 Laravel 中修复,因为在配置文件中使用闭包是一种不好的做法。参考这个 Github问题

The way I solved this is by undo-ing this.

我解决这个问题的方法是撤销这个。

Delete the cache for config.

删除配置缓存。

It is located in here

它位于这里

bootstrap/cache/config.php

bootstrap/cache/config.php

OR

或者

vendor/config.php

vendor/config.php

回答by Jaimin

I had faced the similar issue in past don't know what caused it but as of now you can delete the config.phpfrom /vendorit won't break your code.

我曾面临类似的问题在过去不知道什么原因造成的,但到现在为止,你可以删除config.php/vendor它不会破坏你的代码。

And your code will be start working..

你的代码将开始工作..

回答by Ben Johnson

Among other root-causes, this error results from calling php artisan config:cachewhen a closure is defined inside any configuration file that Laravel attempts to load. Laravel does not allow for closures in configuration files; see:

在其他根本原因中,此错误php artisan config:cache是由于在 Laravel 尝试加载的任何配置文件中定义了闭包时调用造成的。Laravel 不允许在配置文件中使用闭包;看:

https://github.com/laravel/framework/issues/9625

https://github.com/laravel/framework/issues/9625

Deleting the resultant cache file, usually located at bootstrap/cache/config.php, "fixes" the error.

删除生成的缓存文件,通常位于bootstrap/cache/config.php,“修复”错误。

The long-term solution is to eliminate closures from all configuration files. The problematic config file can be determined by inspecting the offending line, as mentioned in the error message.

长期解决方案是消除所有配置文件中的闭包。如错误消息中所述,可以通过检查有问题的行来确定有问题的配置文件。

If the offending file is third-party, it is best to open an issue with the library, so that the issue is fixed upstream.

如果违规文件是第三方的,最好打开库的问题,以便上游修复问题。

回答by Kal

Here is what I did to solve it:

这是我为解决它所做的:

  1. Go to /vendor/tymon/jwt-auth/src/config/config.php and replace the lines for storageand authwith:
  1. 转到/vendor/tymon/jwt-auth/src/config/config.php和更换线storageauth用:

'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter',
'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter'

'auth' => 'Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter',
'storage' => 'Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter'

  1. Go to /bootstrap/cache/config.phpand delete it
  2. Run the following commands in order:
    A) php artisan config/cache
    B) php artisan jwt:generate
    C) php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"
  1. 转到/bootstrap/cache/config.php并删除它
  2. 按顺序运行以下命令:
    A) php artisan config/cache
    B) php artisan jwt:generate
    C)php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\JWTAuthServiceProvider"

and that should do it!

那应该这样做!

回答by giapnh

Try to remove the config.php from bootstrap/cachefolder. It worked for me.

尝试从bootstrap/cache文件夹中删除 config.php 。它对我有用。

回答by Saurabh Mistry

solved using

解决了使用

composer update

composer install

回答by Omar Abu Elyazeed

Changing the config.phpfile inside the vendor/tymon/jwt-auth/src/configto this

config.php里面的文件改成vendor/tymon/jwt-auth/src/config这个

'auth' => Tymon\JWTAuth\Providers\Auth\IlluminateAuthAdapter::class` 

and this

和这个

'storage' => Tymon\JWTAuth\Providers\Storage\IlluminateCacheAdapter::class` 

before runnning php artisan config:cacheworked for me.

在跑步之前php artisan config:cache为我工作。