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

lara28580's avatar

How to make sure input can only be set after certain date

I am trying to figure out how to make sure a text input can only be set after certain date. In my case ends_at Someone has an idea?

'ends_at' => 'nullable|date|after_or_equal:starts_at',
'video_text' => 'nullable|string|max:255|before_or_equal:ends_at',
0 likes
3 replies
Tray2's avatar

You can do something like this

'published_year' => ['required',
		 'numeric',
		 'min_digits:4', 
		'max_digits:4', 
'between:1800,'.Carbon::now()->addYear(1)->year],
1 like
lara28580's avatar

@Tray2 Thanks for the answer but how should that work with ends_at? ends_at is interpreted as string.

Tray2's avatar
Tray2
Best Answer
Level 73

@SmokeTM Why is it a string if it is a date?

However you are aware that you can write your own validation rules?

https://laravel.com/docs/9.x/validation#custom-validation-rules

I have a few in the app I'm building, here for example I check for a valid isbn.

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\InvokableRule;
use Nicebooks\Isbn\IsbnTools;

class Isbn implements InvokableRule
{
    public function __invoke($attribute, $value, $fail): void
    {
        $tools = new IsbnTools();
        if (! $tools->isValidIsbn($value)) {
            $fail('The :attribute must be a valid ISBN10 or ISBN13.');
        }
    }
}

And this is how I use it

 'isbn' => ['required', new Isbn()],
1 like

Please or to participate in this conversation.