Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel Google 2fa二维码未显示_Php_Laravel_Image_Svg - Fatal编程技术网

Php Laravel Google 2fa二维码未显示

Php Laravel Google 2fa二维码未显示,php,laravel,image,svg,Php,Laravel,Image,Svg,我目前正在使用Google 2fa的一个包,并从我的控制器中以字符串变量的形式引入SVG QR码,然后根据包的要求添加QR码。问题是,这不会显示图像,我认为这是由于我从控制器中提取的字符串值造成的 这是我从控制器收到的变量值: public function register(Request $request) { //Validate the incoming request using the already included validator method

我目前正在使用Google 2fa的一个包,并从我的控制器中以字符串变量的形式引入SVG QR码,然后根据包的要求添加QR码。问题是,这不会显示图像,我认为这是由于我从控制器中提取的字符串值造成的

这是我从控制器收到的变量值:

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']]);
    }

在我的blade文件中回显时,它只是回显字符串值。如果我在不使用“”的情况下复制此字符串值,Laravel会将该值识别为html并显示我的二维码。有没有办法让blade将其识别为html代码?或者,当以这种方式将SVG文件作为变量拉入时,如何在刀片文件中显示它?如果有人能帮助我,我将不胜感激

链接到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>

这应该相当容易:

<div>
     {!! $QR_Image !!}
</div>

{!!$QR\U图像!!}

您需要
{!!!!}
来呈现HTML/SVG数据而不转义它。您需要删除img标记,因为它不是真实的图像,而是SVG。

这应该相当容易:

<div>
     {!! $QR_Image !!}
</div>

{!!$QR\U图像!!}

您需要
{!!!!}
来呈现HTML/SVG数据而不转义它。您需要删除img标记,因为它不是一个真实的图像,而是一个SVG。

您试图调试这个问题的原因是什么?您是否可以共享任何涉及的代码?请尝试
{!!$QR\U Image!!}}
-它正在转义它。问题:如果要嵌入静态SVG图像,您会选择
。。。“>
…?不,你不会吗?那么,为什么要在这里做同样的事情呢?如果希望通过图像元素的
src
属性将SVG代码嵌入到数据URI中,那么需要将SVG代码转换为数据URI。你试过调试这个问题吗?您是否可以共享任何涉及的代码?请尝试
{!!$QR\U Image!!}}
-它正在转义它。问题:如果要嵌入静态SVG图像,您会选择
。。。“>
…?不,你不会吗?那么,为什么要在这里做同样的事情呢?如果希望通过图像元素的
src
属性将SVG代码嵌入到数据URI中,那么需要将SVG代码转换为数据URI。谢谢你,法基,真管用!真不敢相信这么简单,我感谢你的时间!谢谢你,法基,真管用!真不敢相信这么简单,我感谢你的时间!