所以我有一个GameAcc模型,里面有以下值:
protected $fillable = [
'AccountName', 'AccountLevelCode', 'SecondAuthFailCount', 'SecondAuthCode', 'SecondAuthLockFlag', 'CharacterCreateLimit', 'CharacterMaxCount', 'RegisterDate', 'PublisherCode', 'NxLoginPwd',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password',
];
当有人在我的网站注册时,GameAcc::create查询将与常规User::create一起执行。它看起来像这样:
// Create the user
$user = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'password' => bcrypt($request->input('password'))
]);
// Create the game account
GameAcc::create([
'AccountName' => $request->input('name'),
'AccountLevelCode' => 0,
'SecondAuthFailCount' => 0,
'SecondAuthCode' => 1,
'SecondAuthLockFlag' => 'false',
'CharacterCreateLimit' => 10,
'CharacterMaxCount' => 8,
'RegisterDate' => Carbon::now(),
'PublisherCode' => 0,
'NxLoginPwd' => $request->input('password')
]);
现在,GameAcc进入一个sqlsrv数据库,而用户信息进入一个常规的mysql数据库。如您所见,NxLoginPwd
没有使用bcrypt,因为从sqlsrv读取密码的程序需要用MD5散列,所以bcrypt是不可用的。
理想情况下,我需要它做的是:
GameAcc::create([
'AccountName' => $request->input('name'),
'AccountLevelCode' => 0,
'SecondAuthFailCount' => 0,
'SecondAuthCode' => 1,
'SecondAuthLockFlag' => 'false',
'CharacterCreateLimit' => 10,
'CharacterMaxCount' => 8,
'RegisterDate' => Carbon::now(),
'PublisherCode' => 0,
'NxLoginPwd' => strtoupper(md5($request->input('password')))
]);
但我知道这行不通。那么我有什么选择继续使用bcrypt与User::create,但使用md5与GameAcc::create?
我已经看过Eloquent mutators,但是在这种情况下似乎没有帮助。
结果是由于某种原因DebugBar出错了。我猜这真的有用!