Skip to content

Instantly share code, notes, and snippets.

@setkyar
Created February 3, 2015 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save setkyar/a5aae9aae219afc93e57 to your computer and use it in GitHub Desktop.
Save setkyar/a5aae9aae219afc93e57 to your computer and use it in GitHub Desktop.
Laravel Validation on Model
/**
* Create a new Elegant class
* And use that class from your model
*/
class Elegant extends Eloquent
{
protected $rules = array();
protected $errors;
public function validate($data)
{
// make a new validator object
$v = Validator::make($data, $this->rules);
// check for failure
if ($v->fails())
{
// set errors and return false
$this->errors = $v->errors();
return false;
}
// validation pass
return true;
}
public function errors()
{
return $this->errors;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment