laravel unique的用法是“'email' => ['required', 'email',Rule::unique('customer')->...})],”,表示更新資訊偵測郵箱是否重複時,排除自己並且排除狀態為4的所有使用者。
本教學操作環境: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中文網其他相關文章!

遷移在laravelmanagedatabaseschema,同時shandledatainterAction.1)遷移術語,允許創造,修改和deletionoftables

SoftDeletsinlaraveRareBetterTernaverainteraldatialdataAndRecoverability,而骨質骨骼驗證了forderableford.fordableablefordataminimization和Privacy.1)softerdeleteseThesoftDeletDeletEstrait,允許restrestoratorralityandaudtrails和mayincroredatabasesize.2)物理

softDeletsinlesInLaravelAlavareAfeAtarowSyOutOmarkRecordsAsdeletedwithOutreMovingThemfromthedataBase.toimplementsoftsoftdeletes:1)addtheSoftDeletDeleteStraittRaittRaiteRemodoyouRmodeNClandInclandInclandEncludEthedeletdelet_atcolumted_atcolumn.2)

laravelmigrationsareefectectivectiveDueTotheirversionControlandRoranderibalsible,slepliningDatabasemagementInwebDevelopment.1)heSpapsulatesCheMachangeNphpClasses,允許easyerollbacks

LaravelMigrationsareArareBestWhenFollowingTheSepractices:1)用戶清除,描述性formigrations,例如'addemailtouserstable'.2)ensuremigrationsareReereSareReverSiblewitha'down'method.3)考慮到the the the the the the the the the the the the the the broaderimptactondataintegnegrityAndegrityAndegrinegrityAndertality.4)optimizeperformanceb

使用Laravel和Vue.js可以構建單頁面應用(SPA)。 1)在Laravel中定義API路由和控制器,處理數據邏輯。 2)在Vue.js中創建組件化前端,實現用戶界面和數據交互。 3)配置CORS和使用axios進行數據交互。 4)利用VueRouter實現路由管理,提升用戶體驗。

在Laravel中創建自定義輔助函數的步驟是:1.在composer.json中添加自動加載配置;2.運行composerdump-autoload更新自動加載器;3.在app/Helpers目錄下創建並定義函數。這些函數能簡化代碼,提高可讀性和可維護性,但需注意命名衝突和測試性。

在Laravel中處理數據庫事務時,應使用DB::transaction方法,並註意以下要點:1.使用lockForUpdate()鎖定記錄;2.通過try-catch塊處理異常,並在需要時手動回滾或提交事務;3.考慮事務的性能,縮短執行時間;4.避免死鎖,可使用attempts參數重試事務。這段摘要完整地概括瞭如何在Laravel中優雅地處理事務,並提煉了文章中的核心要點和最佳實踐。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

Atom編輯器mac版下載
最受歡迎的的開源編輯器

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。