Laravel-Model-Validation icon indicating copy to clipboard operation
Laravel-Model-Validation copied to clipboard

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

Open upwebdesign opened this issue 10 years ago • 2 comments

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.

upwebdesign avatar Aug 29 '13 21:08 upwebdesign

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();
}

lsousa avatar Dec 05 '13 19:12 lsousa

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

zeckdude avatar Feb 10 '15 08:02 zeckdude