【问题标题】:Call to undefined method Illuminate\Validation\Rules\In::__set_state()调用未定义的方法 Illuminate\Validation\Rules\In::__set_state()
【发布时间】:2018-06-03 05:45:04
【问题描述】:

我尝试了各种方法来解决这个问题,比如清除缓存、作曲家更新/安装,但在php artisan config:cache 之后,它又出现了。

在 config.php 第 839 行:
调用未定义的方法 Illuminate\Validation\Rules\In::__set_state()

整个页面变成空白页面。 在 bootstrap/cache/config.php 文件中显示:

'environment' => 
    array (
      'form' => 
      array (
        'rules' => 
        array (
          'app_name' => 'required|string|max:50',
          'environment' => 'required|string|max:50',
          'environment_custom' => 'required_if:environment,other|max:50',
          'app_debug' => 
          array (
            0 => 'required',
            1 => 
            Illuminate\Validation\Rules\In::__set_state(array(
               'rule' => 'in',
               'values' => 
              array (
                0 => 'true',
                1 => 'false',
              ),
            )),
          ),

【问题讨论】:

  • 请说明你在哪里使用这些请求规则,如果是表单请求,你在哪里注入。
  • 我认为它的环境错误,但不知道在哪里?
  • 我认为您需要一个前导斜线,不是吗? \Illuminate\Validation\Rules\In

标签: php laravel laravel-5 laravel-5.5 laravel-validation


【解决方案1】:

我也收到了这个错误,因为不是

“照亮\验证\规则”

我放了

“照亮\合同\验证\规则”

【讨论】:

    【解决方案2】:

    这是laravel/framework/src/Illuminate/Validation 包的问题。

    Rules 文件夹内,我们有一个名为In 的类(文件In.php

    缺少函数__set_state

    如果你要在这个类中添加以下函数,

    static public function __set_state($array = []){
            return 'boolean';
        }
    

    问题将得到解决。此外,它是临时解决方案(composer install/update 命令可以删除您的功能

    享受...

    【讨论】:

      【解决方案3】:

      我认为您有一些带有验证规则的配置文件。验证是否有config/environment.php 文件或验证其他配置文件。

      我认为其中一个你有:

      Rule::in([true, false]);
      

      你不应该在配置文件中使用这个语法,因为它不能被缓存,你应该使用:

      'in:1,0'
      

      然而,在配置文件中保留任何验证规则似乎很奇怪。

      【讨论】:

      • 我已经检查过了,但那里没有这样的文件和验证,这最近发生在我更新作曲家时。
      • @vinodbhandary 首先搜索 required_if:environment,other|max:50 在您的代码中出现的位置
      • 感谢兄弟,我终于得到了它,因为它在移除它后工作了一个包。
      • 谢谢!这段代码帮助我找到问题所在
      【解决方案4】:

      只需删除文件 config.php

      来自引导程序/缓存/

      然后运行

      command composer dumpautoload
      

      php artisan config:cache
      

      对我有用

      【讨论】:

        【解决方案5】:

        Rule::in([true, false]); 更改为'in:1,0' 对我有用。我还需要删除 bootstrap/cache/config.php 中对 Rule 类的所有奇怪引用。

        【讨论】:

          【解决方案6】:

          删除文件

          config.php

          来自

          引导/缓存/

          然后运行命令composer dumpautoload

          php artisan config:cache

          【讨论】:

            【解决方案7】:

            添加此代码:

            use Illuminate\Validation\Rule;
            

            【讨论】:

            • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2015-09-23
            • 2018-10-02
            • 2023-03-23
            • 2020-04-07
            • 2020-03-16
            • 2016-11-18
            • 2014-04-23
            相关资源
            最近更新 更多