Carbon - 「本日を含む一ヶ月以内」であるかどうかチェック
ポイント
-
staftOfDay()
で時刻をリセットする - Carbonは
Carbon::now()
を上書きする-
copy()
を忘れずに
-
-
between
は第3引数で=
ありの>
<
かどうかを指定- trueのとき
=
あり
- trueのとき
Validator::extend("WithinAMonth", function ($attribute, $value, $parameters, $validator) {
if ($value && \DateTime::createFromFormat("Y/m/d", $value)) {
$date = Carbon::createFromFormat("Y/m/d", $value)->startOfDay();
$today = Carbon::now()->startOfDay();
$nextMonthDay = $today->copy()->addMonth();
if ($date->between($today, $nextMonthDay, true)) {
return true;
}
return false;
}
return false;
});
Author And Source
この問題について(Carbon - 「本日を含む一ヶ月以内」であるかどうかチェック), 我々は、より多くの情報をここで見つけました https://qiita.com/shosho/items/6b1b4afa1e23115834a4著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .