Level 73
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
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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',
@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()],
Please or to participate in this conversation.