Last active
August 29, 2015 14:02
-
-
Save gravitano/16853c35418061cded3f to your computer and use it in GitHub Desktop.
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 namespace Pingpong\Traits; | |
use Input, Redirect, Validator; | |
trait ValidatorTrait | |
{ | |
protected $validator; | |
public function validate(array $input = null) | |
{ | |
$data = is_null($input) ? Input::all() : $input; | |
$this->validator = Validator::make($data, $this->getRules(), $this->getMessages()); | |
return $this->validator->passes(); | |
} | |
public function getRules() | |
{ | |
return $this->rules; | |
} | |
public function getMessages() | |
{ | |
return object_get($this, 'messages', array()); | |
} | |
public function getErrors() | |
{ | |
return $this->validator->messages(); | |
} | |
public function redirectFails() | |
{ | |
return Redirect::back() | |
->withInput() | |
->withErrors($this->getErrors()) | |
->withFlashMessage("There was validation errors.") | |
->withFlashType('danger') | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment