Each rule can be used as a macro, or as an instance.
The date-input
component is slightly unusual from a Laravel validation point of view, as it is submitted in three parts.
These rules check to make sure that the specified date exists, and must be applied to a rule against the main name
of the input.
[
'birth' => [
'required',
new BeforeDate(Carbon::now()),
],
'birth-day' => [
// Not here
],
]
You may provide the name of a field as the second parameter to add a time input, which will validate both date and time.
[
'birth-time' => [
'required',
new TimeFormat(),
],
'birth-date' => [
'required',
new BeforeDate(Carbon::now(), 'birth-time'),
],
]
Ensure that the submitted date is after a particular day.
Rule::afterDate(Carbon::now())
// or
new AfterDate(Carbon::now())
Ensure that the submitted date is before a particular day.
Rule::beforeDate(Carbon::now())
// or
new BeforeDate(Carbon::now())
Ensure that the submitted date is on a particular day.
Rule::onDate(Carbon::now())
// or
new OnDate(Carbon::now())
Ensure that the submitted date is on or after a particular day.
Rule::onOrAfterDate(Carbon::now())
// or
new OnOrAfterDate(Carbon::now())
Ensure that the submitted date is on or before a particular day.
Rule::onOrBeforeDate(Carbon::now())
// or
new OnOrBeforeDate(Carbon::now())
Validate that a given time is valid.
These Rules only check the time; date validation must be run separately.
Ensure that the submitted time is after a particular hour and minute.
Rule::afterTime(Carbon::now())
// or
new AfterTime(Carbon::now())
Ensure that the submitted time is on or after a particular hour and minute.
Rule::atOrAfterTime(Carbon::now())
// or
new AtOrAfterTime(Carbon::now())
Ensure that the submitted time is on or before a particular hour and minute.
Rule::atOrBeforeTime(Carbon::now())
// or
new AtOrBeforeTime(Carbon::now())
Ensure that the submitted time is on a particular hour and minute.
Rule::atTime(Carbon::now())
// or
new AtTime(Carbon::now())
Ensure that the submitted time is before a particular hour and minute.
Rule::beforeTime(Carbon::now())
// or
new BeforeTime(Carbon::now())
Ensure that the given time is in a format that PHP can interpret.
Time can be input in many different ways, including 12 and 24 hour formats.
Accepting as many different time formats will ensure the user can specify the time in a way that makes sense to them.
A full list of the formats this rule will accept is available in the class definition.
Rule::timeFormat()
//or
new TimeFormat()
If you are using an input with a words counter, you may wish to ensure that the limit is enforced server-side with some rules.
Ensure that there are max
words or fewer for the given value:
Rule::maxWords(10)
// or
new MaxWords(10)
Ensure that there are min
words or more for the given value:
Rule::minWords(5)
// or
new MinWords(5)
Ensure that there are between min
and max
words in the given value:
Rule::wordsBetween(5, 10)
// or
new WordsBetween(5, 10)