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

相关推荐
车载测试工程师4 小时前
车载以太网网络测试-29【SOME/IP-SD】-SD状态机
网络·网络协议·tcp/ip·车载系统·php
还鮟13 小时前
CTF Web PHP弱类型与进制绕过(过滤)
php·ctf
zorro_z13 小时前
PHP语法基础篇(八):超全局变量
php
九分源码1 天前
基于PHP+MySQL组合开发开源问答网站平台源码系统 源码开源可二次开发 含完整的搭建指南
mysql·开源·php
RainSerein1 天前
Laravel8中使用phpword生成word文档
word·php·laravel
pltrue1 天前
Go 重构案例分享:订单创建逻辑重构
go·php
RainSerein1 天前
Laravel8中调取腾讯云文字识别OCR
ocr·php·腾讯云·laravel
杰哥技术分享1 天前
PHP Yii2 安装SQL Server扩展-MAC M4 Pro芯片
开发语言·php
wuk99811 天前
深入理解PHP中的生成器(Generators)
开发语言·php
A5资源网11 天前
为WordPress 网站创建一个纯文本网站地图(Sitemap)
前端·数据仓库·html·php