我想用Google Authenticator进行两因素身份验证来制作注册表。在尝试注册新用户帐户并扫描生成的QR码然后按完整的注册按钮时,我只是遇到了错误
FatalThrowableError类型错误:参数1传递给 Illuminate \ Http \ Request :: merge()必须为数组类型,为null 给定的 C:\ xampp \ htdocs \ repository \ app \ Http \ Controllers \ Auth \ RegisterController.php 在第113行
这是我的注册控制人
public function register(Request $request)
{
//first we will validate the incoming request
$this->validator($request->all())->validate();
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// store registration data in an array
$registration_data = $request->all();
// Create new secret key to the registration data
$registration_data["google2fa_secret"] = $google2fa->generateSecretKey();
// store registration data to the user session for new request
$request->session()->flash('registration_data', $registration_data);
// Create the QR image.
$QR_Image = $google2fa->getQRCodeInline(
config('app.name'),
$registration_data['email'],
$registration_data['username'],
$registration_data['google2fa_secret']
);
// Send the QR barcode image to our view
return view('google2fa.register', ['QR_Image' => $QR_Image, 'secret' => $registration_data['google2fa_secret']]);
}
public function completeRegistration(Request $request)
{
// add the session data back to the request input
$request->merge(session('registration_data')); <- I got error because of this line (in line 113)
// Call the default laravel authentication
<br>return $this->registration($request);
}
这是路线地址
Route::get('/complete-registration', 'Auth\RegisterController@completeRegistration');
我已经在上方的注册控制器中输入了completeRegistration方法
答案 0 :(得分:0)
使用if
条件检查registration_data
是否为空。
if (session('registration_data') != '' && session('registration_data') != null)
{
$request->merge(session('registration_data'));
}
答案 1 :(得分:0)
您需要这样使用
$request->merge(['registration_date'=>session('registration_data')]);