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

What if I dont want to save a field but only validate the field? #6

Open upwebdesign opened 11 years ago

upwebdesign commented 11 years ago

Ive run into a situation where I would like to validate a field such as Credit Card Expiration and CVV, but I do not want to save the data in the database. At this point Eloquent is complaining that the fields are not in the database and throwing an SQL error. I need the fields to be validated before attempting to charge the credit card. After I am done, I just want to throw away the data.

Is there any way around this? I cannot seem to find a way. Ive also attempted to use various properties such as $guarded and $fillable.

Im sure I will just have to rethink my logic once I find out the answer to this question. Meaning, I will have to validate outside the model validation in this case.

Using Laravel 4.

Thanks.

Ps. nice service BTW.

lsousa commented 10 years ago

If I'm understanding your question correclty (english isn't my main language), you could do something like this:

$dog = new Dog(Input::all());
$validate = $dog->validate();
if (!$validate) {
    $errors = $dog->getErrors();
}
zeckdude commented 9 years ago

Was there a fix or workaround for this issue? I'm experiencing it as well.