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

相关推荐
万联WANFLOW6 小时前
多分支企业组网,IP 网段到底该怎么规划
开发语言·php
WZF-Sang10 小时前
网络基础——2
服务器·网络·c++·学习·网络编程·php
行思理10 小时前
fastadmin 新手部分功能点
后端·php
用户30745969820711 小时前
# GatewayWorker 入门指南
php
2601_9637713716 小时前
Optimizing Logistics and Transportation Sites on WordPress
前端·数据库·windows·php
草邦设计开发团队_媒体资源平台17 小时前
Linux 稳定常驻启动 PHP 队列,服务器重启自动恢复
linux·服务器·php·队列执行
2601_9637713717 小时前
Speeding Up Creative Agency Portfolios: A Performance Guide
前端·数据库·php
七夜zippoe18 小时前
OpenClaw 数据加密:敏感信息保护的完整方案
数据库·mysql·php·openclaw·敏感保护
烤代码的吐司君2 天前
Redis IO 多路复用原理与引入原因深度解析
数据库·redis·php
鹏易灵2 天前
C++——8.移动语义初探(移动构造、移动赋值)
开发语言·c++·php