Support the ongoing development of Laravel.io →
Requests Validation

I use form model binding with a eloquent relation like customer -> hasOne -> adres. Everything on the form and database updates is working well.

In my request validation I can do something like:

  public function rules() {


    return [
      'adres.firstname' => 'required|min:5',
    ];
  }

This is working well, but I don't like the error message: "The adres.firstname field is required."

I should be able to change the error message in validation.php:

  'custom' => [
    'adres.firstname' => [
      'required' => 'Please enter your first name',
    ],
  ],

But it is not accepting "adres.firstname"? Just a single fieldname will work. Can somebody explain to me how I can change the message?

I tried the attributes in validation.php as well but it has the same problem.

What actually is working is add a messages function:

public function messages() {
  $messages = [];
  $messages['adres.firstname.required'] = 'Please fill in your first name!';
  return $messages;
}

But I build a multi language site, and I don't know how to translate this way.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Arie arie Joined 13 Aug 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.