douduan9129 2014-03-29 01:49
浏览 104
已采纳

Laravel 4 - Ardent - 密码确认不匹配

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) "asdasd@asd.com" 
  ["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.

  • 写回答

5条回答 默认 最新

  • dongzheng3113 2014-03-31 17:07
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊