Search code examples
phplaravel-4ardent

Laravel 4 - Ardent - The password confirmation does not match


So I am working on an implementation of Ardent in Laravel 4 and I can't seem to sort out why this password confirmation just won't match.

My user controller looks likes this:

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
use LaravelBook\Ardent\Ardent;

class User extends Ardent implements UserInterface, RemindableInterface {

public static $rules = array(
  'first_name'            => 'required|min:2|max:80|alpha',
  'last_name'             => 'required|min:2|max:80|alpha',
  'email'                 => 'required|between:3,64|email|unique:users',
  'postal_code'           => 'required|min:5|max:80',
  'password'              => 'required|between:4,20|confirmed',
  'password_confirmation' => 'same:password',
  'timezone_id'           => 'required|numeric',
);

public $autoPurgeRedundantAttributes = true;

Then in the model store action I have the following:

$user = new User(Input::all());
if($user->save()) {
  // does a bunch of stuff
}

But in the end the password confirmation warning is persistant and I can't seem to sort out why? If I take the confirmed option off the password field all works well. I can't seem to get them to understand they are the same. I have included a sample var_dump below that I have tested and confirmed it doesn't pass the validation.

array(10) { 
  ["_token"]=> string(40) "726lKBQgckGuLBxmJZ7Kjq4kzzXqADDqv3ZSnMOE" 
  ["first_name"]=> string(3) "asd" 
  ["last_name"]=> string(3) "asd" 
  ["email"]=> string(14) "[email protected]" 
  ["postal_code"]=> string(7) "XXX XXX" 
  ["new_game_notification"]=> string(1) "1" 
  ["timezone_id"]=> string(1) "5" 
  ["password"]=> string(6) "asdasd" 
  ["password_confirmation"]=> string(6) "asdasd" 
  ["role"]=> string(7) "regular" 
}

I was doing my own password hashing before save but in an effort to sort this out I have removed that for now.

Any suggestions or guidance / direction is greatly appreciated.


Solution

  • So as it turns out I have found the solution to this.

    Ironically, the pasword_confirmation needs to be set as fillable on the model to exist for the validation on Ardent to be able to see it and run the validation.

    Fairly simple solution, although not really documented, as why would you put a variable in the fillable array for the model if there isn't a field for it in the database.