3

雄弁なバリデーターメソッドが本来とは逆の結果を返すことに問題があるようです。

これが私の検証呼び出しです。必要な最小値が 2 の場合、電子メールが重複しており、名が 1 文字しかないため、失敗するはずです。

// Handle the submission of changed user details.
public function put_settings()
{
    $id = Input::get('id');

    $validation = Account::validate(Input::all());

    if($validation->fails())
    {
        return Redirect::to_route('settings')->with_errors($validation)->with_input();
    }
    else
    {
        Account::update($id, array(
            'first_name' => Input::get('first_name'),
            'last_name'  => Input::get('last_name'),
            'email'      => Input::get('email')
        ));

        return Redirect::to_route('settings');
    }
}

これは、検証ルールを使用したバリデーターメソッドです (モデル内にあります):

public static function validate($data)
{
    $rules = array(
        'first_name' => 'required|min:2|max:80',
        'last_name'  => 'required|min:2|max:80',
        'email'      => 'required|min:5|max:180|unique:users',
    );

    return Validator::make($data, $rules);
}

検証に失敗したにもかかわらず、これがデータベースを更新するのはなぜですか。fail() メソッドと pass() メソッドの両方を試してみましたが、本来あるべきこととは逆のことをしているようです。何か案は?

4

1 に答える 1

1

Have you tried debugging out the inputs and see what's actually submitted?

Also, you might want to check auth.php to see if you have selected email to be considered as your username for your users. That way if you call unique:users then Laravel will look at email column instead of username column.

于 2012-08-12T11:30:27.180 に答える