Created
July 31, 2016 07:00
-
-
Save sworup/46af4ecdf4ebe542615f1568dfab1e76 to your computer and use it in GitHub Desktop.
Laravel- Add after hook in request file. Reference: https://goo.gl/8BhhCB
This file contains hidden or 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 | |
/** | |
* Get the validator instance for the request and | |
* add attach callbacks to be run after validation | |
* is completed. | |
* | |
* @return \Illuminate\Contracts\Validation\Validator | |
*/ | |
protected function getValidatorInstance() | |
{ | |
return parent::getValidatorInstance()->after(function($validator){ | |
// Call the after method of the FormRequest (see below) | |
$this->after($validator); | |
}); | |
} | |
/** | |
* Attach callbacks to be run after validation is completed. | |
* | |
* @param \Illuminate\Contracts\Validation\Validator $validator | |
* @return callback | |
*/ | |
public function after($validator) | |
{ | |
if ($this->somethingElseIsInvalid()) { | |
$validator->errors()->add('field', 'Something is wrong with this field!'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment