Sam Debruyn

Freelance Data & Cloud Architect

Specialized in Microsoft Azure, Fabric & modern data stack. Microsoft Data Platform MVP. dbt Community Award. Public speaker & meetup organizer. OSS contributor.

Sam Debruyn

Workaround for password confirmation with Laravel & Ardent

1 minutes

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):

1public static $rules = array(
2    'email' => 'required|email|max:100|unique:users',
3    'password' => 'required|min:6|confirmed',
4);

Your model should also have the following line somewhere:

1public $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.

1protected $fillable = array('email', 'password', 'activation_code', 'confirmed', 'reset_password', 'password_confirmation');

You might also like

If you liked this article, follow me on LinkedIn or other social media to stay up-to-date with my latest posts. You might also like the following 2 posts about related topics: