搜索
首页php框架Laravellaravel unique的用法是什么

laravel unique的用法是什么

Dec 27, 2021 pm 02:39 PM
laravelunique

laravel unique的用法是“'email' => ['required', 'email',Rule::unique('customer')->...})],”,表示更新信息检测邮箱是否重复时,排除自己并且排除状态为4的所有用户。

laravel unique的用法是什么

本教程操作环境:windows7系统、Laravel5.5版,DELL G3电脑。

Laravel unique规则使用

laravel的unique的用法:

      $customer_type = request('customer_type', 1);
        $attributes = request()->validate([
            'gender' => 'required|min:0|max:3',
            'chinese_name' => 'nullable|min:2',
            'english_name' => 'nullable|min:3',
            'area_phone_number' => 'required|numeric',
            'telephone' => 'required|numeric',
            'email' => ['required', 'email', Rule::unique('customer')->ignore(request('id'))->where(function ($query) {
                $query->whereNotIn('status', [4]);
            })],
            // 'email' => 'required|email|unique:customer,email,' . request('id'),
            'password' => 'nullable|string|min:6',
            'concurrent_login_num' => 'required|min:1|integer',
            'child_age' => 'nullable|integer|min:0',
            'remark' => 'nullable|string|max:1024',
            'status' => 'required|integer|min:0|max:4',
        ]);

注意一下这个用法:

'email' => ['required', 'email', Rule::unique('customer')->ignore(request('id'))->where(function ($query) {
                $query->whereNotIn('status', [4]);
            })],

这个意思是更新信息检测邮箱是否重复的时候,排除自己,并且排除状态为4的所有用户,我这里,状态为4的用户是删除的状态。如果这个邮箱是被删除的用户所使用,那么,也不检验重复性。

参考资料:https://laravel.com/docs/5.5/validation
文件位置:
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Rules\DatabaseRule.php
关于各种的的验证:
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Concerns\ValidatesAttributes.php
D:\phpStudy\WWW\BCCKidAdmin\vendor\laravel\framework\src\Illuminate\Validation\Concerns\ReplacesAttributes.php

相关推荐:最新的五个Laravel视频教程

以上是laravel unique的用法是什么的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最后的Laravel版本:迁移教程最后的Laravel版本:迁移教程May 14, 2025 am 12:17 AM

Laravel的迁移系统在最新版本中提供了哪些新功能和最佳实践?1.新增了nullableMorphs()用于多态关系。2.引入了after()方法来指定列顺序。3.强调处理外键约束以避免孤立记录。4.建议优化性能,如适当添加索引。5.提倡迁移的幂等性和使用描述性名称。

Laravel的最新LTS版本是什么?Laravel的最新LTS版本是什么?May 14, 2025 am 12:14 AM

Laravel10,释放的2023年,IstheLatestltSversion,支持Forthreyear。

保持更新:最新的Laravel版本中的最新功能保持更新:最新的Laravel版本中的最新功能May 14, 2025 am 12:10 AM

Laravel的最新版本引入了多个新功能:1.LaravelPennant用于管理功能标志,允许分阶段发布新功能;2.LaravelReverb简化了实时功能的实现,如实时评论;3.LaravelVite加速了前端构建过程;4.新的模型工厂系统增强了测试数据的创建;5.改进了错误处理机制,提供了更灵活的错误页面自定义选项。

在Laravel中实现软删除:逐步教程在Laravel中实现软删除:逐步教程May 14, 2025 am 12:02 AM

SoftleteTeinElelelverisling -Memptry -BraceChortsDevetus -teedeeceteveveledeveveledeecetteecetecetecedelave

当前Laravel版本:检查最新版本和更新当前Laravel版本:检查最新版本和更新May 14, 2025 am 12:01 AM

laravel10.xisthecurrentversion,offeringNewFeaturesLikeEnumSupportineloQuentModelsAndModersAndImpreverModeModeModelBindingWithenums.theSeupDatesEupDatesEnhanceCodereadability andSecurity andSecurity和butquirecareecarefulecarefulecarefulplanninganninganningalmplementAlimplemplemplemplemplemplempletationForupforupsupflade。

如何使用Laravel迁移:逐步教程如何使用Laravel迁移:逐步教程May 13, 2025 am 12:15 AM

laravelmigrationsStreamLinedAtabasemangementbyallowingbolAlyChemachangeStobEdeDinedInphpcode,whobeversion-controllolleDandShared.here'showtousethem:1)createMigrationClassestodeFinePerationFineFineOperationsLikeCreatingingModifyingTables.2)

查找最新的Laravel版本:快速简便的指南查找最新的Laravel版本:快速简便的指南May 13, 2025 am 12:13 AM

要查找最新版本的Laravel,可以访问官方网站laravel.com并点击右上角的"Docs"按钮,或使用Composer命令"composershowlaravel/framework|grepversions"。保持更新有助于提升项目安全性和性能,但需考虑对现有项目的影响。

使用Laravel的更新:使用最新版本的好处使用Laravel的更新:使用最新版本的好处May 13, 2025 am 12:08 AM

youshouldupdateTotheLateStlaravelVerverSionForPerformanceImprovements,增强的安全性,newfeatures,BetterCommunitySupport,and long-term-Maintenance.1)绩效:Laravel9'Selover9'seloquentormoptimizatizationenenhanceApplicationsPeed.2)secuse:laravel8InIntrododeDodecter.2)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

VSCode Windows 64位 下载

VSCode Windows 64位 下载

微软推出的免费、功能强大的一款IDE编辑器

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)