如何在Laravel中的Validator中更改数据库

Nar*_*kon 5 php laravel laravel-4

我想通过这种方式验证来自控制器操作的请求值:

    // validate the info, create rules for the inputs
    $rules = array(
        'username'        => 'required|min:5|unique:users,username',
        'email'           => 'required|email|unique:users,email',
        'password'        => 'required|min:8',
    );

    // run the validation rules on the inputs from the form
    $validator = Validator::make(Input::all(), $rules);
Run Code Online (Sandbox Code Playgroud)

如果我使用默认数据库,一切都很好,但对于此验证,我需要检查其他数据库中的表.在配置中我有两个数据库:

    'connections' => array(

    'main' => array(
        'driver'    => 'mysql',
        'host'      => '*******',
        'database'  => '*******',
        'username'  => '*******',
        'password'  => '*******',
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
        'prefix'    => 'ko_',
    ),

    'server_auth' => array(
        'driver'    => 'mysql',
        'host'      => '*******',
        'database'  => '*******',
        'username'  => '*******',
        'password'  => '*******',
        'charset'   => 'utf8',
        'collation' => 'utf8_general_ci',
        'prefix'    => '',
    ),
),
Run Code Online (Sandbox Code Playgroud)

当我调用验证时,它正在我的默认数据库中通过"唯一"规则进行检查,因此我需要更改它,但我无法在任何地方找到如何执行此操作.

Nar*_*kon 9

我这样做了:

    $verifier = App::make('validation.presence');
    $verifier->setConnection('server_auth');

    // validate the info, create rules for the inputs
    $rules = User::$rules = array(
        'username'        => 'required|min:5|unique:users,username',
        'email'           => 'required|email|unique:users,email',
        'password'        => 'required|min:8',
    );

    // run the validation rules on the inputs from the form
    $validator = Validator::make(Input::all(), $rules);

    $validator->setPresenceVerifier($verifier);
Run Code Online (Sandbox Code Playgroud)

解决其他有此问题的人.