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

相关推荐
Helen_cai2 小时前
OpenHarmony 通用状态加载、空页面、错误兜底组件封装(全局业务通用 UI 组件 API23)
开发语言·ui·华为·php·harmonyos
REDcker3 小时前
基于 eBPF 的网络可观测:协议栈路径与 sk_buff
linux·服务器·网络·php·ebpf·bpf
weixin_BYSJ19871 天前
django在线图书销售平台---附源码16192
java·javascript·spring boot·python·django·flask·php
__log2 天前
弱网环境下的“生命线“:从AI流式响应到大文件上传的稳定性
开发语言·人工智能·php
TlSfoward2 天前
TLSFOWARD TLS指纹
开发语言·数据库·爬虫·搜索引擎·https·php
信仰8742 天前
Linux进阶篇01:网络基础配置
linux·网络·php
Qlittleboy2 天前
PHP的接口参数传递的过多,max_input_vars = 5000
开发语言·php
谪星·阿凯2 天前
CTF Web 解题完全指南:从 PHP 弱类型到 SSTI 模板注入的实战方法论
前端·安全·php·ctf web
你驴我2 天前
WhatsApp 多账号消息路由中的去重与顺序保证实践
开发语言·php
酷可达拉斯2 天前
Linux操作系统-简单内核优化
linux·git·php