2

I am creating a CRUD using dimsav translatable and proengsoft/laravel-jsvalidation packages for Laravel. The form field names have to follow an array structure like this...

<div class="form-group">
    {!! Form::label("es[title]", trans("messages.title"), ["class" => "control-label"]) !!}
    {!! Form::text("es[title]", getFormInput($entry, "title", $locale), ["class" => "form-control", "id" => "es[title]"]) !!}
</div>

To be able to use mass asignment easily on the controller.

The create form is being validated with a CreateRequest as follows...

{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
         return [
             'es.title' => 'required|max:255',           
         ];
    }
}

I don't know how to change the attribute placeholders with more friendly texts at resources/lang/validation.php file. I have tried the following options...

'attributes' => [      
    'title' => 'título',
    //'es.title' => 'título',       
    //'es[title]' => 'título',       
],

...but any of them is working. The form is being validated ok naming the field 'es.title' but the error message showed is not replacing the field name correctly even if I name the attributes array key also 'es.title'. Any ideas?

1
  • I think proengsoft/laravel-jsvalidation is not a good package Commented Nov 3, 2016 at 17:14

1 Answer 1

4

Inside App/Http/Requests/YourRequest

public function messages()
    {
        return [
            'es.title.required' => 'You forgot título!',
        ];
    }

You can set different messages for different validation rules(required,max etc)

For setting up custom name for an attribute

public function attributes()
{
    return [
        'es.title' => 'título'
    ];
}

EDITED For setting up attribute name globally go to lang/en/validation and you'll see an attribute array. Change it according to you requirement.

'attributes' => [
    'es' => [
        'title' => 'título'
    ]
],
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks but that's not what I wanted. I want to be able to change the field name on the attributes array for each validation.php.
@HarleyFuagras updated my answer. please check and see if it works.
Yep, that's what I was trying and it's not working. You can see it in the last piece of code of my question.
sorry my bad. posted wrong code. Updated again. Please check now

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.