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

rmatelec's avatar

How to create a custom message in a Request class.

Hi, I've just created a new Request to use in my controller with the command artisan make:request.

My doubt is if is there a way to add the value content inside messages() method.

My request is something similar to:


    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'email' => 'required|email|unique:mysql.users,email',
            'birthdate' => 'required|date|before:today',
        ];
    }

    public function messages(): array
    {
        return [
            'email' => 'The email is already taken.',
        ];
    }

I would like to return a message in case it fails like: "The email '[email protected]' is already taken".

Thank you so much! :)

0 likes
2 replies
Dunsti's avatar
Dunsti
Best Answer
Level 6

you can add the user input with the :input placeholder

like so:

return [
            'email' => 'The email :input is already taken.',
        ];
1 like

Please or to participate in this conversation.