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

chalssdev's avatar

Date validation rules

Hello, I'm trying to create my first validation file and I don't know how to make that the dateStart =< dateEnd. I've searched on Google and I looked at the docs but I don't find it. I think that this should be very easy to do :/

    public function rules()
    {
        return [
            'name' => 'required|max:255',
            'dateStart' => 'required|date',
            'dateEnd' => 'required|date|after:dateStart',
        ];
    }

Another question is, What is the better way to validate that a user is owning a message (for example) and he can edit this message. If the user_id of the message don't match with the Auth:user, the user should not be able to edit. What is the cleaner way? I searched on google but there is a lot of possible answers.

Thanks.

0 likes
1 reply
chalssdev's avatar
chalssdev
OP
Best Answer
Level 1

Sorry for posting but finally I have the answer, fyu:

    public function rules()
    {
        return [
            'name' => 'required|max:255',
            'dateStart'  => 'required|date|date_format:Y-m-d|after:yesterday',
            'dateEnd'    => 'required|date|date_format:Y-m-d|after:' . \Carbon\Carbon::parse($this->dateStart)->subDay()->toDateString(),
        ];
    }

Please or to participate in this conversation.