Skip to content

Instantly share code, notes, and snippets.

@allanphilipbarku
Last active May 25, 2021 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allanphilipbarku/b76b49d99c3789926ee30ae34905a017 to your computer and use it in GitHub Desktop.
Save allanphilipbarku/b76b49d99c3789926ee30ae34905a017 to your computer and use it in GitHub Desktop.
Laravel Year Validation
<?php
$this->validate(
$request,[
'year' => 'integer|required|digits:4|min:1900|max:' . (date('Y') - 1),
]
);
?>
@allanphilipbarku
Copy link
Author

The year concatenated is minus 1 to limit it to the previous year. Carbon can be used to be more accurate with the cut off date

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment