取得したフォームを 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'
);
そして、すべてのフィールドで必要なエラーが発生します!
- 電子メール フィールドは必須です。
- メール確認フィールドは必須です。
- 疑似フィールドは必須です。
- 性別フィールドは必須です。
- 出生フィールドは必須です。
- wilaya コード フィールドは必須です。
- パスワードフィールドは必須です。
- パスワード確認フィールドは必須です。
更新 : 見る
{{ 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と互換性のあるビュースクリプトはありますか? ありがとうございました
update : 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)