Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

polarcubs's avatar

Date range validation

Hi,

Currently I have a model called Lesson and as expected I have fields such as

teacher_id start_time end_time day_of_week (i.e. Wednesday, Friday)

Using Model based validation solutions such as Laravel validating as well as Laravel Administrator. I'm required to have a $rules variables defining the validation rules in my models and admin config files.

My question is therefore, how do I specify validation rules such as end_time always be after start_time, the date range start_time and end_time does not clash with other lessons created by the same teacher?

The validation docs in Laravel shows something like

$v->sometimes('reason', 'required|max:500', function($input)
{
    return $input->games >= 100;
});

However for my case I'm just using a rules variable here. Would like to know the normal way of doing it too with the $v->sometimes option.

0 likes
1 reply

Please or to participate in this conversation.