philipbrown / magniloquent

DEPRECATED, USE https://github.com/dwightwatson/validating
MIT License
70 stars 8 forks source link

Nice names in validation #27

Closed RicardoRamirezR closed 10 years ago

RicardoRamirezR commented 10 years ago

In some case is desirable to have a nice attribute names

/**
 * @var array nice attribute names
 */
protected $niceNames = array();

and in the validator...

public function validate()
{
    // Merge the rules arrays into one array
    $this->mergeRules();

    $validation = Validator::make($this->attributes, $this->mergedRules, $this->customMessages);

    $validation->setAttributeNames($this->niceNames);

    if ($validation->passes())
    {
        $this->valid = true;

        return true;
    }

    $this->validationErrors = $validation->messages();

    return false;
}
w3irdrobot commented 10 years ago

What would be the use of this?

RicardoRamirezR commented 10 years ago

When you have a column name and you want to give more information to the user, i.e., column name is expires and to the users you want to say "The expiration date should be...", instead of "The expires should be..."

http://laravel.com/docs/validation#custom-error-messages

Zn4rK commented 10 years ago

This would also help with localisation of the attribute names...

w3irdrobot commented 10 years ago

Sorry, I misunderstood. This would be a great addition! Please submit a pull request, and we will pull it in ASAP.