JeffreyWay / Laravel-Model-Validation

This Laravel package auto-validates a model on save.
https://packagist.org/packages/way/database
275 stars 54 forks source link

Confirmed rule not working #31

Closed henriquebremenkanp closed 9 years ago

henriquebremenkanp commented 9 years ago

First of all... Happy new year :)

Problem

Validation rules that rely in other attributes that not itself (like confirmed that requires foo_confirmation) will always fail. All validation attributes that are not $fillable will always fail too. In case someone wants to validate a field but not store it.

Cases

Password confirmation:

$rules = ['password' => 'confirmed'];
$fillable = ['foo', 'password'];
--
User::create(Input::only('foo', 'password', 'password_confirmation')); // Even if matches, validation fails.

Cause

Attributes passed to Validator::make() are the model attributes which some are previously removed by $fillable rules. We also don't want to make fields like "password_confirmation" fillable as it will throw a QueryException because that collumn doesn't exist.

Fix

Use all the input received instead of $this->attributes so everything can be validated. (Like we would do in a "traditional validation workflow" if we can call it that way)

henriquebremenkanp commented 9 years ago

this may also be related into closing #6 and #11