laravel 表单验证的 exists、unique 去除软删除字段的校验

use Illuminate\Validation\Rule;

exists 去除软删除字段的校验

php 复制代码
	$validator = \Validator::make($data, [
		'phone_new' => [
          	Rule::exists('users', 'phone')->whereNull('deleted_at'),
      	]
  	], [
      	'phone_new.exists' => '手机号不存在',
  	]);

unique 去除软删除字段的校验

php 复制代码
// 新增
'email'=>'required|email|unique:users,email,NULL,id,deleted_at,NULL'

'email' => ['required', Rule::unique('users')->whereNull('deleted_at')]

// 修改
'email'=> "required|email|unique:users,email,{$this->id},id,deleted_at,NULL"

'email' => ['required', Rule::unique('users')->ignore($this->id)->whereNull('deleted_at')]

补充

冒号后面6个空,前两个不用说,中间两个表示忽略id=$this->id,后面两个表示加上限定条件deleted_at=null

相关推荐
liudanzhengxi2 小时前
AnthropicAPI连接超时:实战避坑指南
开发语言·php
号码认证服务4 小时前
客户看到来电显示公司名会更愿意接听吗?企业号码认证提升ROI
服务器·网络·c++·经验分享·智能手机·云计算·php
yoyo_zzm4 小时前
汇编到PHP:五大编程语言核心特性全解析
开发语言·汇编·php
yoyo_zzm4 小时前
编程语言大比拼:C++到PHP全解析
开发语言·c++·php
山栀shanzhi4 小时前
TCP 三次握手四次挥手
服务器·tcp/ip·php
yoyo_zzm5 小时前
ThinkPHP3.X:经典PHP框架的全面解析
开发语言·php
号码认证服务7 小时前
小米、OPPO、VIVO手机支持号码认证显示公司名吗?
java·服务器·网络·经验分享·智能手机·云计算·php
ZHOUPUYU7 小时前
PHP8高性能Web开发实战指南
后端·html·php
yoyo_zzm7 小时前
六大编程语言核心差异全解析
c语言·c++·spring boot·php
yoyo_zzm7 小时前
四大编程语言对比:C/C++/C#/PHP
c++·c#·php