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

t-b's avatar
Level 1

Laravel 9 validation message rules value not see

Hello friends,

When I use the After and Before rules in Laravel 9, I cannot get the value that should belong to the rules within the rules I defined in the Validation class in the message section. I am writing the example below. The error message reads like this:

Date :after has to be big

or

Date :before has to be small

Date 11/30/2022 has to be small or Date 11/01/2022 has to be big


public function rules(): array
    {
        return [
            'name' => 'required|min:2',
            'date=> 'required|after:11/01/2022|before:11/30/2022',
        ];
    }

public function messages(): array
    {
        return [
            'name.required' => 'Please Enter Username',
            'name.min' => 'Username must contain at least :min characters',
            'date.required' => 'Please Select Date',
            'date.after' => 'Date :after has to be big',
            'date.before' => 'Date :before has to be small',
        ];
    }

0 likes
10 replies
Sinnbeck's avatar

Use a proper date format. This is a computer, not an american :)

2022-11-30 for example

t-b's avatar
Level 1

@sinnbeck thanks for your answer.

but when I cancel manipulating messages, laravel gives the error message ?

It's also the same when I tried it the way you said. It doesn't work when I edit in the messages method.

Sinnbeck's avatar

@tbahadir what does this mean?

but when I cancel manipulating messages, laravel gives the error message ?

t-b's avatar
Level 1

@Sinnbeck

It works fine when I remove the error message inside the messages method.

Ex:

If the message is not defined in the messages method:

 The date must be a date before 2022-30-11. 

If the message is defined in the messages method:

 Date date has to be small 

I tried as you forwarded, the answer is as follows:

 Date date has to be small 
Sinnbeck's avatar

Try this

public function messages(): array
    {
        return [
            'name.required' => 'Please Enter Username',
            'name.min' => 'Username must contain at least :min characters',
            'date.required' => 'Please Select Date',
            'date.after' => 'Date :attribute has to be big',
            'date.before' => 'Date :attribute has to be small',
        ];
    }
Sinnbeck's avatar

Or

public function messages(): array
    {
        return [
            'name.required' => 'Please Enter Username',
            'name.min' => 'Username must contain at least :min characters',
            'date.required' => 'Please Select Date',
            'date.after' => 'Date :date has to be big',
            'date.before' => 'Date :date has to be small',
        ];
    }

Btw what does "Date date has to be big" or "Date 2011-02-11 has to be big" mean?

t-b's avatar
Level 1

@Sinnbeck The messages it gives are not important here, I will change the texts. only the definitions of rules that we always use do not change in the message.

I also tried the example you sent last time, the answer is as follows:

 Date :date has to be small 

Also, let me repeat, the messages come as follows:

 Date :after has to be big
 Date :before has to be small 
t-b's avatar
Level 1

Thanks a lot for your help @Sinnbeck .

In after before uses, we get the limit value with :date :) while I was reading that part of your message.

I hope this thread helps if anyone else has the same problem as me.

The final version of the code is as follows;


public function rules(): array
    {
        return [
            'name' => 'required|min:2',
            'date=> 'required|after:2022/01/11|before:2022/30/11',
        ];
    }

public function messages(): array
    {
        return [
            'name.required' => 'Please Enter Username',
            'name.min' => 'Username must contain at least :min characters',
            'date.required' => 'Please Select Date',
            'date.after' => 'Date :date has to be big',
            'date.before' => 'Date :date has to be small',
        ];
    }

Please or to participate in this conversation.