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

asdasdsa's avatar

How to validate a date, or a string.

Hi!

I have a field that is suppost to be a date. But now i have decided to also have the ability to enter a string. Why you might ask? Because that I store some data of a specifik product both in the US, Europe and Japan. And it would be nice to actually see if that product hasent been release in that region.

        $request->validate([
            'europe_release' => 'nullable|date_format:Y-m-d'
        ]);

So how can i add the ability to add the option to enter "not released" with this date_format?

Thanks!

0 likes
9 replies
jlrdw's avatar

I would have not released as a separate field, maybe a boolean.

bobbybouwmann's avatar

The suggestion of @jlrdw is also good, to use a different field to make this work and hide the date field in the UI

3 likes
< GDB >'s avatar

is your string only "not released"? If so, what about a simple if statement if the date is blank = string "not released"

asdasdsa's avatar

@gillesdeb Yeah good input! But the date could also be unknown, that why.

But i think i will go with the boolean option.

A checkbox with the validation of required_unless:anotherfield,value,... and also for the date_format will have the required_unless:anotherfield,value,.... Or am i wrong?

Snapey's avatar

how can you store this state in your database?

Better to have a boolean that tells you if the date is used then you can store both released and release_date

laracoft's avatar

@asdasdsa

  • If europe_release == NULL then it is not released
  • If europe_release != NULL then it was released on europe_release

Please or to participate in this conversation.