ポイント
-
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;
});