我正在尝试使用 User::$rules 验证检索到的表单,并且验证总是返回失败,所有必需的字段!当我死并Input::All()
在控制器中转储时,我得到了提交表单时提供的所有输入字段,这意味着问题出在模型中,对吗?我从来没有遇到过这么奇怪的问题!请帮忙
控制器:用户控制器
public function postSinscrire() {
$validator = Validator::make(Input::all(), User::$rules);
if($validator->passes()) {
$user = new User;
$user->email = Input::get('email');
$user->email_confirmation = Input::get('email_confirmation');
$user->number = Input::get('number');
$user->pseudo = Input::get('pseudo');
$user->banned_user = 0;
$user->activation_email = 0;
$user->activation_number = 0;
$user->sex = Input::get('sex');
$user->birth = Input::get('birth');
$user->wilaya_code = Input::get('wilaya_code');
$user->user_type = 1;
$user->password = hash::make(Input::get('password'));
$user->password_confirmation('password_confirmation');
$user->save();
return Redirect::to('membre')
->with('message', 'Welcome');
}
if($validator->failed()) {
return Redirect::to('membre/sinscrire')
->with('message','Une erreur s\'est produise, Corrigez puis réessayez a nouveau')
->withErrors($validator)
->withInput();
}
型号:用户
protected $hidden = array('password', 'remember_token');
protected $fillable = array(
'email','number','pseudo','sex','birth','wilaya_code',
);
public static $rules = array(
'email'=>'max:254|unique:users|email|required',
'email_confirmation'=>'max:254|unique:users|email|required',
'number'=>'between:8,15|unique:users',
'pseudo'=>'max:35|unique:users|required|alpha_num',
'banned_user'=>'boolean|integer',
'activation_email'=>'boolean|integer',
'activation_number'=>'boolean|integer',
'sex'=>'boolean|integer|required',
'birth'=>'required|date',
'wilaya_code'=>'integer|required|max:2',
'activation_date'=>'date',
'user_type'=>'integer',
'password'=>'required|between:8,12|alpha_num|confirmed',
'password_confirmation'=>'required|between:8,12|alpha_num'
);
然后我得到所有字段所需的错误!
- 电子邮件字段是必需的。
- 电子邮件确认字段是必需的。
- 伪字段是必需的。
- 性别字段是必需的。
- 出生字段是必需的。
- 维拉亚代码字段是必需的。
- 密码字段是必需的。
- 密码确认字段是必需的。
更新:查看
{{ Form::open(array(
'url'=>'membre/sinscrire',
'method'=>'POST'
)) }}
<label for="email">Email :</label>
{{ Form::text('email')}} <br>
<label for="email_confirmation">Email :</label>
{{ Form::text('email_confirmation')}} <br>
<label for="pseudo">Identifiant ( pseudo ) :</label>
{{ Form::text('pseudo')}} <br>
<label for="password">Mot de passe :</label>
{{ Form::password('password')}} <br>
<label for="password_confirmation">Confirmation :</label>
{{ Form::password('password_confirmation')}} <br>
<label for="gender">Sexe :</label>
{{ Form::select('gender',array('0'=>'Homme', '1'=>'Femme'))}} <br>
<label for="sana_hilwa">Date de naissance :</label>
{{ Form::selectRange('year', 1930, 2011); }}
{{ Form::selectRange('month', 01, 12); }}
{{ Form::selectRange('day', 01, 31); }} <br>
<label for="al_wilaya">Wilaya :</label>
{{ Form::select('al_wilaya', array(
'1' => 'Adrar',
'2' => 'Chlef',
'31' => 'Oran'
)) }} <br>
En cliquant sur “Je m'inscris”, vous indiquez que vous avez lu, compris et accepté les <a href="/apropos"><strong>conditions d\'utilisation</strong></a> de Ouedkniss. <br>
{{ Form::submit('Inscrivez vous')}}
{{ Form::close()}}
当我dd('Input::all');
array (size=11)
'_token' => string 'mCVboVC123456789nDpOJZXyjiY5YsUrjRMGunPx' (length=40)
'email' => string 'foo@bar.com' (length=11)
'email_confirmation' => string 'foo@bar.com' (length=11)
'pseudo' => string 'foo' (length=3)
'password' => string 'testpass' (length=8)
'password_confirmation' => string 'testpass' (length=8)
'gender' => string '0' (length=1)
'year' => string '1930' (length=4)
'month' => string '1' (length=1)
'day' => string '1' (length=1)
'al_wilaya' => string '1' (length=1)
注意:从视图中未正确完成出生字段
我希望只获得所需的出生字段,如果这是问题,任何与 Carbon 兼容的视图脚本?谢谢
更新:DD('User::$rules');
array (size=14)
'email' => string 'required|max:254|email|unique:users|confirmed' (length=45)
'email_confirmation' => string 'required|max:254|email|unique:users' (length=35)
'number' => string 'between:8,15|unique:users' (length=25)
'pseudo' => string 'required|alpha_num|max:35|unique:users' (length=38)
'banned_user' => string 'boolean|integer' (length=15)
'activation_email' => string 'boolean|integer' (length=15)
'activation_number' => string 'boolean|integer' (length=15)
'sex' => string 'required|boolean|integer' (length=24)
'birth' => string 'required|date' (length=13)
'wilaya_code' => string 'required|max:2|integer' (length=22)
'activation_date' => string 'date' (length=4)
'user_type' => string 'integer' (length=7)
'password' => string 'required|between:8,12|alpha_num|confirmed' (length=41)
'password_confirmation' => string 'required|between:8,12|alpha_num' (length=31)