【问题标题】:Laravel Validation Rule 'same' Always FailsLaravel 验证规则“相同”总是失败
【发布时间】:2017-07-14 10:46:22
【问题描述】:

控制器中的验证

$this->validate($req, [
  'password' => ['required', 'string', 'min: 6', 'same: conf_password'],
  'conf_password' => ['required', 'string', 'min: 6', 'same: password'],
]);

查看

<input id="password" type="password" class="form-control" name="password" 
  placeholder="Enter password" value="{{ old('password') }}">

<input id="conf_password" type="password" class="form-control" 
   name="conf_password" placeholder="Enter password once again"
   value="{{ old('conf_password') }}">

它总是返回 false,即使我将其更改为 confirmed 规则并使用 _confirmation 后缀规范。

但我做了dd($req-&gt;password == $req-&gt;conf_password),它返回true。发生了什么?

【问题讨论】:

  • 你试过删除:之后的空格吗?
  • @cweiske 谢谢老兄,你救了我的命。我只搜索了 3 个小时的空间。
  • 你为什么不用confirmedlaravel.com/docs/5.4/validation#rule-confirmed
  • @RossWilson 我做了,但什么也没发生,仍然失败。

标签: php laravel laravel-5 laravel-5.4


【解决方案1】:

删除:之后的空格。

【讨论】:

  • 为什么same 规则有严格的格式,而regex、min 和其他规则却没有。天哪。
  • 为 laravel 打开一个 bug。
  • @YosuaLijantoBinar,请记住接受这个答案。
猜你喜欢
  • 2015-04-04
  • 2019-01-19
  • 1970-01-01
  • 2014-05-20
  • 2018-12-21
  • 2019-12-23
  • 1970-01-01
  • 2016-01-18
  • 2020-06-02
相关资源
最近更新 更多