使用条件Laravel验证用户

I just want to ask how to log-in a user with a certain condition. Currently I'm using this code:

if (Auth::attempt(array('username'=>Input::get('username'), 'password'=>Input::get('password')))) 
{
    return Redirect::to('/')->with('message', 'You are now logged in!');
} 

with the above code, I'm able to login a user as long as its username and password matched on my db. But now I want to add a condition that I will only accept a user that has a role_id 1 or 2. Role_id is a field in my user table.

How do I do that? Sorry, I'm just starting to learn laravel 4.

You just need to add the key/value pair you want to validate inside the array you're passing into Auth::attempt(). In your case, something like the following would do the job:

Auth::attempt(array('username' => $username, 'password' => $password, 'role_id' => $role)

Laravel will then search for the row with the matching username and role_id and return the first result.