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

相关推荐
2501_916007478 小时前
TCP 抓包分析实战,从三次握手到自定义协议解析的完整方法
网络协议·tcp/ip·ios·小程序·uni-app·php·iphone
真正的醒悟12 小时前
图解网络22
服务器·网络·php
云梦谭15 小时前
AI 生成的FreeSWITCH 呼出流程深度分析freeswitch-1.10.12.-release
java·前端·php
上海云盾-小余17 小时前
DDoS 攻击溯源:DNS 水印标记 + 区块链存证的双保险
区块链·php·ddos
Web极客码17 小时前
CentOS与RHEL安装EPEL源解析错误修复
linux·centos·php
catchadmin17 小时前
如何创建和使用 Shell 脚本实现 PHP 部署自动化
开发语言·自动化·php
杰哥技术分享17 小时前
宿主机(CentOS)没有安装 PHP,但想使用php
linux·centos·php
m0_7381207217 小时前
渗透测试——靶机Sar1渗透横向详细过程
开发语言·python·安全·web安全·网络安全·ssh·php
济南壹软网络科技有限公司18 小时前
壹软V4Max 旗舰版:定义新一代盲盒电商生态系统
php·盲盒源码·盲盒h5·国际盲盒源码
BingoGo19 小时前
万物皆字符串 PHP 中的原始类型偏执
后端·php