Created
August 20, 2019 13:57
-
-
Save fhdalikhan/1e9fdebab35c00e1ee7b46d3fdccf6a3 to your computer and use it in GitHub Desktop.
Carbon Macro For Laravel, Useful To Test For Valid Date.
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 | |
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