Hi, I’m using October version 2.x and have a form that has a “master” date range, and then a series of “sub” date ranges that must be within the start and end dates of the master date range.
For for example, if the master date range start = 2024-01-01 and end = 2024-05-01, then all of the sub date ranges in the form must have start and end dates between those two master date range dates.
valid:
2024-01-01 to 2024-03-01
2024-02-01 to 2024-05-01
invalid:
2023-12-31 to 2024-03-01 (start date is outside of range)
2024-01-01 to 2024-05-02 (end date is outside of range)
I’ve read up on the custom validation but the docs seem incomplete. It’s very vague about creating the rules file, and refers to the laravel docs which say to use make:rule, but that’s not even a command in october, etc.
use Model;
class YourModel extends Model
{
public $rules = [
'sub_date' => 'after:2024-01-01|before:2024-05-01',
];
// Other model code...
}
In your beforeSave function…
use Model;
class YourModel extends Model
{
// Other model code...
public function beforeSave()
{
$startDate = strtotime('2024-01-01');
$endDate = strtotime('2024-05-01');
if (strtotime($this->start_date) <= $startDate) {
throw new \Exception('Start date must be after January 1, 2024.');
}
if (strtotime($this->end_date) >= $endDate) {
throw new \Exception('End date must be before May 1, 2024.');
}
}
}
The ‘after_or_equal’ rule is helpful for another issue I was having, didn’t know that existed since it’s not in the documentation (Validation - October CMS - 2.x). Is there anywhere where I can see a full list of all validation rules?