· PHP laravel

Workaround for password confirmation with Laravel & Ardent

While I was working on a website made with Laravel and Ardent I had to validate a password confirmation field for a user registration. This will not work if you follow the standard documentation.

This is how your validation rules in your Ardent model should look like (users only have an email address and a password):

public static $rules = array(
    'email' => 'required|email|max:100|unique:users',
    'password' => 'required|min:6|confirmed',

Your model should also have the following line somewhere:

public $autoPurgeRedundantAttributes = true;

Now, if you follow the documentation and include every database field in the fillable array, validation will always fail on the password confirmation.

The workaround is to include the password confirmation field in the fillable array, even if it isn’t a column in your database.

protected $fillable = array('email', 'password', 'activation_code', 'confirmed', 'reset_password', 'password_confirmation');
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pocket
About the author

Samuel Debruyn is a C# developer who builds mobile (cross platform) apps with Xamarin. Sam is a certified Xamarin mobile developer since 2016. He likes to experiment with all kinds of programming languages and software frameworks. More info