yakczh
2014-04-09 09:23:47 +08:00
没有映射,耦合性就太强了,要么在表单域的名字全部与数据库表字段一致,要么在controll/route里面挨个赋值 $data = array(
'user_login' => Input::get('f1'),
'user_password' => Input::get('f3'),
'user_email' => Input::get('f2'),
);
然后按表字段来验证
$rules= array(
'user_login' => 'required',
'user_password' => 'required|min:8',
'user_email' => 'required|email|unique:users'
);
$validator = Validator::make($data, $rules);
但这样验证出错信息里是表字段为键
Array ( [*messages] => Array ( [user_login] => Array ( [0] => The user login field is required. ) [user_password] => Array ( [0] => The user password field is required. ) [user_email] => Array ( [0] => The user email field is required. ) ) [*format] => :message )
前台在显示错误提示的时候 只显示The following errors have occurred: 但不会显示具体那个字段出错了,因为找不到对应的键,除非用
{{ $errors->first('user_login', '<li>:message</li>') }}
{{ $errors->first('user_password', '<li>:message</li>') }}
{{ $errors->first('user_email', '<li>:message</li>') }} 再把数据库表名全部列上去,这样就跟第一种方式一样了