Skip to content

Instantly share code, notes, and snippets.

@reinink
Created March 1, 2017 20:11
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reinink/8111e414051c6216e2a6ed3153ef74a4 to your computer and use it in GitHub Desktop.
Save reinink/8111e414051c6216e2a6ed3153ef74a4 to your computer and use it in GitHub Desktop.
Laravel request validation macros
<?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