Last active
August 29, 2015 14:05
-
-
Save martinbean/31fdafe13d1faa6e5634 to your computer and use it in GitHub Desktop.
Laravel validation trait.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
trait ValidatorTrait { | |
protected $validator; | |
public function isValid() | |
{ | |
return $this->getValidator()->passes(); | |
} | |
public function getValidator() | |
{ | |
return Validator::make($this->attributes, $this->rules); | |
} | |
public function getErrors() | |
{ | |
return $this->getValidator()->errors(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Import the trait, and then define a
$rules
property in your model class with the validation rules.And then use as thus: