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

相关推荐
Lhappy嘻嘻6 小时前
Java IO|File 文件操作 + 字节流 / 字符流完整笔记 + 递归删除文件实战
java·笔记·php
2601_963771379 小时前
How to Scale Your WordPress Store Traffic in 2026
前端·php·plugin
右耳朵猫AI13 小时前
PHP周刊2026W28 | 安全更新、Laravel 13.18、Twig 3.28
开发语言·php·laravel
罗政13 小时前
PDF 批量合并工具:本地 AI 自动排序、识别正文日期与合同编号
数据库·pdf·php
糖果店的幽灵15 小时前
安全测试从入门到精通_网络基础与HTTPS
网络·https·php
2601_9637713716 小时前
WordPress SEO Guide: Boost Rankings Without Technical Jargon
前端·php
日取其半万世不竭19 小时前
CS2 服务器搜不到?GSLT、端口和启动参数逐项检查
运维·服务器·php
360智汇云21 小时前
一次Redis超时引发的“冤案“
数据库·redis·php
ljs64827395121 小时前
Linux 网络常用命令与端口基础详解
linux·网络·php
m0_738120722 天前
PHP代码审计基础——超全局变量(三)
开发语言·安全·网络安全·php