Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- Class Validated extends Eloquent {
- public $rules = array();
- public $errors;
- public function __construct($attributes = array(), $exists = false)
- {
- $this->errors = new \Laravel\Messages;
- parent::__construct($attributes, $exists);
- }
- public function save()
- {
- if ($this->is_valid())
- {
- return parent::save();
- }
- else
- {
- // TODO: Valdiation exception obj.
- throw new Exception('Validation error');
- }
- }
- public function is_valid()
- {
- $validator = Validator::make($this->to_array(), $this->rules);
- if ($validator->fails())
- {
- $this->errors = $validator->errors;
- return FALSE;
- }
- else
- {
- return TRUE;
- }
- }
- }
Add Comment
Please, Sign In to add comment