LoginSignup
18
17

More than 5 years have passed since last update.

Laravelの日付バリデーションで現在日時との比較

Last updated at Posted at 2015-07-28

今日以降の日付のみOK

class HogeRequest extends Request
{
    // ...

    public function rules()
    {
        return [
            'start_date' => 'after:yesterday',
        ];
    }
}

yesterdayの他にtomorrow等も使える。

現在時刻以降の日時のみOK

class HogeRequest extends Request
{
    // ...

    public function rules()
    {
        return [
            'start_datetime' => 'after:"now"',
        ];
    }
}

"now + 1 day"で明日の現在時刻以降のみOKとかもできる。

参考

http://laravel.com/docs/5.0/validation
http://laravel-tricks.com/tricks/validation-and-behavior-of-date-date-format-before-and-after-rules
http://stackoverflow.com/questions/29327916/laravel-4-2-date-validation
http://laravel.io/forum/07-21-2014-validating-dates-in-non-us-formats

18
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
17