我正在尝试使用User :: $规则验证检索到的表单,并且验证始终返回失败,并且需要所有字段!当我死了并将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兼容的视图脚本? 谢谢
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)
答案 0 :(得分:0)
仔细检查验证规则。
'email'=>'max:254|unique:users|email|required',
'email_confirmation'=>'max:254|unique:users|email|required'
'number'=>'between:8,15|unique:users',
如果您要更新并使用以前的电子邮件或号码,验证将始终失败。
如果是这种情况,在更新之前,先获取您的电子邮件和号码,然后根据输入数据进行检查。如果它们与现有数据匹配,请不要对这些字段使用验证规则,否则请使用这些验证规则。