rmatelec
5 months ago

How to create a custom message in a Request class.

Posted 5 months ago by rmatelec

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! :)

Please sign in or create an account to participate in this conversation.