gpt4 book ai didi

php - Laravel 验证 : check why validator failed

转载 作者:可可西里 更新时间:2023-10-31 23:04:59 24 4
gpt4 key购买 nike

是否有办法检查验证器是否因 unique 规则而失败?

$rules = array(
'email_address' => 'required|email|unique:users,email',
'postal_code' => 'required|alpha_num',
);

$messages = array(
'required' => 'The :attribute field is required',
'email' => 'The :attribute field is required',
'alpha_num' => 'The :attribute field must only be letters and numbers (no spaces)'
);

$validator = Validator::make(Input::all(), $rules, $messages);

if ($validator->fails()) {

通俗地说,我基本上想知道:“验证失败是因为 email_address 不是唯一的吗?”

最佳答案

检查返回的失败规则数组中的特定规则

if ($validator->fails()) {

$failedRules = $validator->failed();

if(isset($failedRules['email_address']['Unique'])) {

...

关于php - Laravel 验证 : check why validator failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com