Guest User

Untitled

a guest
Oct 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2.  
  3. Class Validated extends Eloquent {
  4.  
  5. public $rules = array();
  6.  
  7. public $errors;
  8.  
  9. public function __construct($attributes = array(), $exists = false)
  10. {
  11. $this->errors = new \Laravel\Messages;
  12.  
  13. parent::__construct($attributes, $exists);
  14. }
  15.  
  16. public function save()
  17. {
  18. if ($this->is_valid())
  19. {
  20. return parent::save();
  21. }
  22. else
  23. {
  24. // TODO: Valdiation exception obj.
  25. throw new Exception('Validation error');
  26. }
  27. }
  28.  
  29. public function is_valid()
  30. {
  31. $validator = Validator::make($this->to_array(), $this->rules);
  32.  
  33. if ($validator->fails())
  34. {
  35. $this->errors = $validator->errors;
  36. return FALSE;
  37. }
  38. else
  39. {
  40. return TRUE;
  41. }
  42. }
  43.  
  44. }
Add Comment
Please, Sign In to add comment