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

maltekiefer's avatar

Format date before validation

This is how I validate some inputs:

        $request->validate([
            'holidaydate' => 'required|unique:holidays,holidaydate,NULL',
            'description' => 'required'
        ]);

Is there a way to format holidaydatebefore I validate it?

0 likes
3 replies
bugsysha's avatar

If you are using Request objects (php artisan make:request) then you can use following:

    /**
     * Prepare the data for validation.
     *
     * @return void
     */
    protected function prepareForValidation()
    {
        //
    }

1 like
Nakov's avatar

Try adding this before the validation line:

$request->merge(['holidaydate' => Carbon::createFromFormat('d/m/Y', $request->input('holidaydate'))->format('m-d-Y')]);

I gave just an example, I don't know the expected format.

Please or to participate in this conversation.