Can I use ardent in laravel to validate fields that I don't want it to save?

StackOverflow https://stackoverflow.com/questions/19682352

  •  01-07-2022
  •  | 
  •  

Вопрос

I want Ardent to check that password and password confirmation match...yet, I obviously don't want to store password confirmation in the database. So how do I get Ardent to do it's stuff and validate but not try to save the password confirmation?

Note: the validation is failing anyway as it is not seeing the password_confirmation property value. I imagine it's looking for it under the model attributes, whereas I have just set it as a private property. If I set it as the model's attribute though, it will try to save this to the database.

public static $rules = array(
        'email' => 'required|email',
        'first_name' => 'required|alphaNum|min:3',
        'surname' => 'required|alphaNum|min:3',
        'password' => 'required|alphaNum|min:6|confirmed',
        'password_confirmation' => 'required'
);

//user object gets populated
$this->save(); 
Это было полезно?

Решение

You give your class a property of

public $autoPurgeRedundantAttributes = true;

And that automatically purges any properties not used in the database, see here.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top