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:phpStudyWWWBCCKidAdminvendorlaravelframeworksrcIlluminateValidationRulesDatabaseRule.php 關于各種的的驗證: D:phpStudyWWWBCCKidAdminvendorlaravelframeworksrcIlluminateValidationConcernsValidatesAttributes.php D:phpStudyWWWBCCKidAdminvendorlaravelframeworksrcIlluminateValidationConcernsReplacesAttributes.php
相關推薦:最新的五個Laravel視頻教程
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END
喜歡就支持一下吧
相關推薦