· 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

In case you have any further questions, remarks or suggestions about this post, feel free to drop me a tweet or an email! You can also find me on Slack on the Xamarin Chat. I go by the username sam_d.

About the author

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