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

I was looking to do the same thing and so I dug into the API and although it often doesn't explain what many things are it at least gives me some hints of what is possible.

Here I see in the API docs (Laravel 4.2) that you can pass an attributes array to the validator class. I just took a quick guess and the following did work:

$attributes = [
    'category_id' => 'Category ID',
    'regid' => 'Registration ID #'
];

$rules = [
    'category_id' => 'required|min:10|max:30|alpha_num',
    'regid' => 'required|digits:10'
];

$validator = Validator::make(Input::all(), $rules, [], $attributes);

You may notice I had no $messages so I simply passed an empty array so defaults were used, however I could have passed those as well.

I would imagine you could use Lang:get('field_name') to fill in your $attributes array values as well.

Please note, I was only making a guess and didn't actually look at the Validator class in more depth (and I am new to Laravel) so perhaps this is more of a hack than a solid solution.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.