php - 我收到错误 FatalThrowableError 类型错误:传递给 Illuminate\Http\Request::merge() 的参数 1 必须是数组类型,给定 null
问题描述
我想使用 Google Authenticator 制作一个具有两个因素身份验证的注册表单。当我尝试注册一个新用户帐户并扫描生成的二维码然后按完成注册按钮时,我收到了一个错误
FatalThrowableError 类型错误:传递给 Illuminate\Http\Request::merge() 的参数 1 必须是数组类型,给定 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
解决方案
使用if
条件来检查是否registration_data
为空。
if (session('registration_data') != '' && session('registration_data') != null)
{
$request->merge(session('registration_data'));
}
推荐阅读
- mobile - 如何在 Katalon Studio 的自动化测试中为检查点重用元素的值
- android - rhino 在安卓手机上运行 javascript 很慢
- django - 数据库中的django模型字段注释
- javascript - 如何将 x->n y->n 对象顺时针旋转 90°?
- javascript - CalHeatmap 在加载数据时调整时间戳时区
- excel - 如果值匹配,则在 Excel 中将多个工作表中的值求和
- android - 使用 AndroidX 导航的 Fragment 中的动态 ActionBar 标题
- java - PreparedStatement SQLException
- ios - UICollectionView reloadData 中的错误
- android - CalendarPicker 视图显示我提前一天的日期