How would you add multiple validation rules to a model?
I've created a BaseModel where the BaseModel extends Eloquent. My other models extends the BaseModel.
models/BaseModel
class BaseModel extends Eloquent {
public $errors;
public function validate($data) {
$validation = Validator::make($data, static::$rules);
if($validation->passes()) {
return true;
}
$this->errors = $validation->messages();
return false;
}
}
models/User
protected static $rules = [
'email_address' => "required|email|unique:users,email_address",
'first_name' => "required",
'last_name' => "required",
'password' => "required|min:6|same:confirm_password",
'confirm_password' => "required:min:6|same:password",
];
The above rules applies to the registration page.
Now my login page will also be going through the Users model.
It should validate the email address and password.
Is it possible to add multiple validation rules to a model.
I'm sure I can just make $rules a variable which gets passed the validation function but that doesn't seem clean. eg
model/BaseModel
public function validate($data, $rules) {