laraval登陸註冊自定義驗證欄位
阿新 • • 發佈:2019-01-08
protected function validator(array $data) { $rules = [ 'vricode'=>'required|string|min:6|max:6', 'smscode'=>'required|string|min:6|max:6', 'phone' => 'regex:/^1[34578][0-9]{9}$/', 'password' => 'required|string|min:6|confirmed', ]; $messages = [ 'vricode'=>':attribute的長度不正確', 'smscode'=>':attribute的長度不正確', 'phone' => ':attribute格式不正確', 'password' => ':attribute不一致', ]; $attributes = [ 'vricode'=>'驗證碼', 'smscode'=>'手機驗證碼', 'phone' => '手機號碼', 'password' => '密碼', ]; return Validator::make($data, $rules, $messages, $attributes); }
使用方法:
在laraval自帶的Http/Controller/Auth/RegisterController.php中