Q:

How to change Database in Validator in Laravel

I want to Validate requested values from controller action by this way:
    // 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);

All is fine if I'm using the default database, but for this Validation I need to check the tables in other database. In config I have two databases:
    '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'    => '',
    ),
),

When I call the Validation, it is checking by "unique" rule in my default database so I need to change it, but I cannot found anywhere how to do this.

A:

I made it by this way:
    $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);

Solution for others who had this problem.

