我目前正在使用 Google 2fa 的包,并从我的控制器中以字符串变量的形式提取 SVG QR 码,然后根据包要求将 QR 码添加为 . 问题是这不显示图像,我认为这是由于我从控制器中提取的字符串值。
在我的刀片文件中回显它时,它只是回显字符串值。如果我要复制没有“”的字符串值,Laravel 会将该值识别为 html 并显示我的二维码。有没有办法回显它让刀片将其识别为 html 代码?或者,当以这种方式将其作为变量拉入时,如何在刀片文件中显示此 SVG 文件?请如果有人能帮助我,将不胜感激!
链接到 Laravel 包 -> https://github.com/antonioribeiro/google2fa-laravel
我的控制器:
public function register(Request $request)
{
//Validate the incoming request using the already included validator method
$this->validator($request->all())->validate();
// Initialise the 2FA class
$google2fa = app('pragmarx.google2fa');
// Save the registration data in an array
$registration_data = $request->all();
// Add the secret key to the registration data
$registration_data["google2fa_secret"] = $google2fa->generateSecretKey();
// Save the registration data to the user session for just the next request
$request->session()->flash('registration_data', $registration_data);
// Generate the QR image. This is the image the user will scan with their app
// to set up two factor authentication
$QR_Image = $google2fa->getQRCodeInline(
config('app.name'),
$registration_data['email'],
$registration_data['google2fa_secret']
);
// Pass the QR barcode image to our view
return view('google2fa.register', ['QR_Image' => $QR_Image, 'secret' => $registration_data['google2fa_secret']]);
}
我的观点:
<div>
<img src="{{ $QR_Image }}">
</div>
九州编程