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

untymage's avatar

Custom date validation

I want a custom rule like this "Your date must be registered 1 weeks after the last record"

For example if the last created_at record on table is 2019-09-28, User input date must be greater than 2019-10-05.

So should i handle this by validation or another things?

0 likes
1 reply
bobbybouwmann's avatar
Level 88

Laravel already has validation rules for that ;)

Documentation: https://laravel.com/docs/6.x/validation#rule-before

You can for example to this your validation rules

$rules = [
    'name' => 'required',
    'date' => 'before:' . now()->addWeek()->format('Y-m-d'),
];

now() is a helper method for \Carbon\Carbon::now() ;)

1 like

Please or to participate in this conversation.