Created
March 1, 2017 20:11
-
-
Save reinink/8111e414051c6216e2a6ed3153ef74a4 to your computer and use it in GitHub Desktop.
Laravel request validation macros
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 | |
Request::macro('validate', function ($rules, $messages = [], $customAttributes = []) { | |
$this->lastValidated = array_keys($rules); | |
(new class() { | |
use ValidatesRequests; | |
})->validate($this, $rules, $messages, $customAttributes); | |
}); | |
Request::macro('validated', function ($rules) { | |
$this->validate($rules); | |
return $this->only(array_keys($rules)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment