Search code examples
phplaravelqr-code

How to save generated qr Code in laravel?


I have generated QR code using "simplesoftwareio/simple-qrcode": https://github.com/SimpleSoftwareIO/simple-qrcode

Now I want to save the generated image in my local drive. How can I do it?

 public function qr($id)
{

    $data = Ticket::get()->find($id);
    $image = \QrCode::format('png')
                     ->merge('img/t.jpg', 0.1, true)
                     ->size(200)->errorCorrection('H')
                     ->generate('A simple example of QR code!');
    return response($image)->header('Content-type','image/png');

    return view('qrCode', compact('qrData', $qrData));
}

Solution

  • You can try

    $image = \QrCode::format('png')
                     ->merge('img/t.jpg', 0.1, true)
                     ->size(200)->errorCorrection('H')
                     ->generate('A simple example of QR code!');
    $output_file = '/img/qr-code/img-' . time() . '.png';
    Storage::disk('local')->put($output_file, $image); //storage/app/public/img/qr-code/img-1557309130.png