Skip to content

Instantly share code, notes, and snippets.

@fhdalikhan
Created August 20, 2019 13:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhdalikhan/1e9fdebab35c00e1ee7b46d3fdccf6a3 to your computer and use it in GitHub Desktop.
Save fhdalikhan/1e9fdebab35c00e1ee7b46d3fdccf6a3 to your computer and use it in GitHub Desktop.
Carbon Macro For Laravel, Useful To Test For Valid Date.
<?php
Carbon::macro('checkDate', function ($year, $month = null, $day = null) {
if (isset($this)) {
throw new \RuntimeException('Carbon::checkDate() must be called statically.');
}
if ($day === null) {
[$year, $month, $day] = explode('-', $year);
}
return checkdate($month, $day, $year);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment