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

chaudigv's avatar

Livewire date validation for e.g. before_or_equal:

Using livewire $rules to validate date.

protected $rules = [
	'start_date' => ['required', 'before_or_equal:' . Carbon::today()],
]

gives error Constant expression contains invalid operations

I even moved the initialisation to mount(), but it produces the same error.

public $today;
protected $rules = [
        'start_date' => ['required', 'before_or_equal:' . $this->today],
]
public function mount()
{
    $this->today = Carbon::today();
}

Am I missing something here?

0 likes
5 replies
MarianoMoreyra's avatar
Level 25

Hi @chaudigv

Try with this:

protected $rules = [
	'start_date' => ['required', 'before_or_equal:today'],
]

Hope this works for you!

5 likes
chaudigv's avatar

Gotcha.

What if we want the date to be a week from now. How would you achieve that without raising the Constant expression contains invalid operations error.

Appreciate your help.

jrdev761's avatar

This is not complete without the date or date_format validation

protected $rules = [ 'start_date' => ['required', 'date_format:d/m/Y', 'before_or_equal:today'],, ]

Please or to participate in this conversation.