laravel unique的用法是“\’email\’ => [\’required\’, \’email\’,rule::unique(\’customer\’)->…})],”,表示更新信息檢測(cè)郵箱是否重復(fù)時(shí),排除自己并且排除狀態(tài)為4的所有用戶。
本教程操作環(huán)境:windows7系統(tǒng)、laravel5.5版,dell g3電腦。
laravel unique規(guī)則使用
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\’, ]);
注意一下這個(gè)用法:
\’email\’ => [\’required\’, \’email\’, rule::unique(\’customer\’)->ignore(request(\’id\’))->where(function ($query) { $query->wherenotin(\’status\’, [4]); })],
這個(gè)意思是更新信息檢測(cè)郵箱是否重復(fù)的時(shí)候,排除自己,并且排除狀態(tài)為4的所有用戶,我這里,狀態(tài)為4的用戶是刪除的狀態(tài)。如果這個(gè)郵箱是被刪除的用戶所使用,那么,也不檢驗(yàn)重復(fù)性。
參考資料:https://laravel.com/docs/5.5/validation文件位置:d:\\\\phpstudy\\\\www\\\\bcckidadmin\\\\vendor\\\\laravel\\\\framework\\\\src\\\\illuminate\\\\validation\\\\rules\\\\databaserule.php關(guān)于各種的的驗(yàn)證:d:\\\\phpstudy\\\\www\\\\bcckidadmin\\\\vendor\\\\laravel\\\\framework\\\\src\\\\illuminate\\\\validation\\\\concerns\\\\validatesattributes.phpd:\\\\phpstudy\\\\www\\\\bcckidadmin\\\\vendor\\\\laravel\\\\framework\\\\src\\\\illuminate\\\\validation\\\\concerns\\\\replacesattributes.php
相關(guān)推薦:最新的五個(gè)laravel視頻教程