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

相关推荐
木木子2213 小时前
[特殊字符] 音乐播放器——状态驱动的多媒体控制
android·开发语言·华为·php·harmonyos
酷酷的身影14 小时前
Drivers/LedManager.cs
开发语言·php
可靠的仙人掌15 小时前
SAC(Soft Actor-Critic)算法底座
开发语言·算法·php
qq_4221525717 小时前
PDF内容复用的几种实用方法:转PPT、转图片、转长图
pdf·php·powerpoint
weixin_BYSJ19871 天前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
用户3074596982072 天前
GatewayWorker 从零到一完整指南
javascript·php
XR1234567882 天前
食品饮料与制药行业GMP合规网络建设:无尘车间的网络不能成为污染源
开发语言·网络·php
AC赳赳老秦2 天前
传感器数据自动汇总:OpenClaw 采集多类传感器数据、清洗入库、生成趋势分析
java·人工智能·python·自动化·github·php·openclaw
Dynadot_tech2 天前
如何拍卖域名
开发语言·php
发光小北2 天前
Bronze100系列plc Modbus及自由口通信案例
开发语言·php