Support the ongoing development of Laravel.io →
Input Validation
Last updated 2 years ago.
0

I can tell you why you get the weird behaviour, but I can't help you with the problem you have overall (though I'd be interested to see the eventual solution).

What's happening here is that :attribute is not being inserted into the string till after the inner Lang::get() call. So here's what happens:

In the validation translation the string it's looking at is: 'The ' . Lang::get('input.:attribute') . ' is required.'

But at the point it retrieves the string from your validation rules it evaluates the inner Lang::get() and so you get:

Lang::get('input.:attribute') → 'input.:attribute' (there is no such key `input.:attribute` so return string unchanged)

Leaving the validation string to be translated as:

The input.:attribute is required.

So then this is translated with the validation rule, complete with ':attribute' insertion, which is why you see:

The input.email is required.

Hopefully that makes sense - basically :attribute is not actually evaluated when you think it will be, but later.

Last updated 2 years ago.
0

I found something at the bottom of the original language file:

'attributes' => array(
    'email' => 'E-mail address',
),

And it is working if I set it to the following (so I can link it to my input.php file):

'attributes' => array(
    'email' => Lang::get('input.email'),
),
Last updated 2 years ago.
0

Aha that makes sense. I was thinking "surely Laravel has a way to localise field names".

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

balintant balintant Joined 2 Apr 2014

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.

© 2024 Laravel.io - All rights reserved.