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

相关推荐
Sagittarius_A*5 小时前
【RCELABS】Level 17~18 —— PHP命令执行函数与环境变量注入
开发语言·安全·web安全·靶场·php·rce
破碎的南瓜5 小时前
靶场中使用到的php函数以及每种漏洞的防御方式
开发语言·php
谁看我谁 狼家二丫5 小时前
局域网文件共享实战:从“账户被禁用”到成功互传文件
开发语言·php
AC赳赳老秦6 小时前
软著公开信息批量采集:OpenClaw 抓取软件著作权公开数据,分析企业技术布局方向
大数据·网络·人工智能·python·php·deepseek·openclaw
梓仁沐白6 小时前
【Agent 设计模式】多智能体协作
microsoft·设计模式·php
开源推荐官7 小时前
刚上架的商品搜不到,tigshop开源商城搜索是怎么查的
mysql·开源·php
Dxy12393102168 小时前
TCP三次握手和四次挥手的过程详解
网络·tcp/ip·php
weixin_BYSJ19871 天前
springboot校园自习室管理小程序---附源码32142
java·javascript·spring boot·python·django·flask·php
大鱼>1 天前
eBPF内核编程:从TC到XDP的全栈可观测性
linux·服务器·php
aixingpan1 天前
aixingpan.cn API开发文档:api_docs_trichart_natal_solararc_transit2接口指南
前端·php