Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stargatesg1's avatar

QR Code Generator

I was wondering if there is a laravel library to generate QR Codes?

0 likes
24 replies
willvincent's avatar

Not laravel specific, but this is the most popular (by huge margin) composer package for QR generation with php: https://packagist.org/packages/bacon/bacon-qr-code

The package @ohffs linked to is more popular, but also does a lot more. If you're only interested in QR it might be overkill -- it also looks like it's only for PDFs, which probably won't help if you just need to place the QR code somewhere and have no use for PDF generation. :)

1 like
stargatesg1's avatar

A lot of that generates PDFs with the content in it. I am looking for something that generates the image QR code.

Cronix's avatar

@qljsystems Yeah, the maintainer either closed or moved the repo with that QR package since that link was posted over year ago. Not sure what brunowerneck can do about that.

Shipment12's avatar

I downloaded qrcode with this=> ' composer require simplesoftwareio/simple-qrcode' trying to use the QrCode in the controller i am getting the error => badmethodcallexception. the error is pointing at the QrCode. i really need help on this as i have been going back and forth for hours

 *
 * @return Response
 */
public function store(CreateQrcodeRequest $request)
{
    $input = $request->all();

     //save data to database
     $qrcode = $this->qrcodeRepository->create($input);

    
    //generate qrcodes

    //save qrcode image in our folder on this site

    $file = 'generated_qrcodes/'.$qrcode->id.'.png';

 

   $newqrcode = QrCode::text('message')  
    ->setSize(4)
    ->setMargin(2)
    ->setOutfile($file)
    ->generate('ItSolutionStuff.com')
    ->png();

    if( $newqrcode){
        $input['qrcode_path'] = $file;

//         //update database
        QrCode::where('id', $qrcode->id)
        ->update([
            'qrcode_path' => $input['qrcode_path']
        ]);
Shipment12's avatar

@VANDAN - sir, the qrcode did not work. its telling me QrCode class is not existing.

Shipment12's avatar

@VAN1310 - this is my QrCodecontroller


namespace App\Http\Controllers;

use App\Http\Requests\CreateQrcodeRequest;
use App\Http\Requests\UpdateQrcodeRequest;
use App\Repositories\QrcodeRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Auth;
use QrCode;
use BaconQrCode;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;

class QrcodeController extends AppBaseController
{
    /** @var  QrcodeRepository */
    private $qrcodeRepository;

    public function __construct(QrcodeRepository $qrcodeRepo)
    {
        $this->qrcodeRepository = $qrcodeRepo;
    }

    /**
     * Display a listing of the Qrcode.
     *
     * @param Request $request
     * @return Response
     */
    public function index(Request $request)
    {
        $this->qrcodeRepository->pushCriteria(new RequestCriteria($request));
        $qrcodes = $this->qrcodeRepository->all();

        return view('qrcodes.index')
            ->with('qrcodes', $qrcodes);
    }

    /**
     * Show the form for creating a new Qrcode.
     *
     * @return Response
     */
    public function create()
    {
        return view('qrcodes.create');
    }

    /**
     * Store a newly created Qrcode in storage.
     *
     * @param CreateQrcodeRequest $request
     *
     * @return Response
     */
    public function store(CreateQrcodeRequest $request)
    {
        $input = $request->all();

         //save data to database
         $qrcode = $this->qrcodeRepository->create($input);

        
        //generate qrcodes

        //save qrcode image in our folder on this site

        $file = 'generated_qrcodes/'.$qrcode->id.'.png';

        

       $newqrcode = QrCode::text('message') 
        ->setSize(4)
        ->setMargin(2)
        ->setOutfile($file)
        ->png();

        if( $newqrcode){
            $input['qrcode_path'] = $file;

    //         //update database
    $newqrcode =  QrCodeModel::where('id', $qrcode->id)
            ->update([
                'qrcode_path' => $input['qrcode_path']
            ]);

           
        }else{
            Flash::success('Qrcode saved successfully.');
        }

            Flash::error('Qrcode unsuccessfully saved.');

        


        

        

        return redirect(route('qrcodes.index'));
     }

    /**
     * Display the specified Qrcode.
     *
     * @param  int $id
     *
     * @return Response
     */    ```
Shipment12's avatar

@VAN1310 - this is my composer.json

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "appointer/swaggervel": "dev-master",
        "bacon/bacon-qr-code": "^1.0",
        "doctrine/dbal": "~2.3",
        "fideloper/proxy": "^4.0",
        "infyomlabs/adminlte-templates": "5.6.x-dev",
        "infyomlabs/laravel-generator": "5.6.x-dev",
        "infyomlabs/swagger-generator": "dev-master",
        "laravel/framework": "5.6.*",
        "laravel/tinker": "^1.0",
        "laravelcollective/html": "^5.6.0",
        "simplesoftwareio/simple-qrcode": "^2.0"
        
    },
    "require-dev": {
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

this is the error i am getting


C:\xampp\htdoz\qrcode\vendor\simplesoftwareio\simple-qrcode\src\SimpleSoftwareIO\QrCode\BaconQrCodeGenerator.php
        $dataType = $this->createClass($method);
 
        $dataType->create($arguments);
 
        return $this->generate(strval($dataType));
    }
 
    /**
     * Creates a new DataType class dynamically.
     *
     * @param string $method
     *
     * @return SimpleSoftwareIO\QrCode\DataTypes\DataTypeInterface
     */
    private function createClass($method)
    {
        $class = $this->formatClass($method);
 
        if (!class_exists($class)) {
            throw new \BadMethodCallException();
        }
 
        return new $class();
    }
 
    /**
     * Formats the method name correctly.
     *
     * @param $method
     *
     * @return string
     */
    private function formatClass($method)
    {
        $method = ucfirst($method);
 
        $class = "SimpleSoftwareIO\QrCode\DataTypes\".$method;
 
        return $class;
    }
Arguments
""

'

Shipment12's avatar

@VAN1310 - more errors


BadMethodCallException
No message


C:\xampp\htdoz\qrcode\app\Http\Controllers\QrcodeController.php
     *
     * @return Response
     */
    public function store(CreateQrcodeRequest $request)
    {
        $input = $request->all();
 
         //save data to database
         $qrcode = $this->qrcodeRepository->create($input);
 
        
        //generate qrcodes
 
        //save qrcode image in our folder on this site
 
        $file = 'generated_qrcodes/'.$qrcode->id.'.png';
 
        
 
       $newqrcode = QrCode::text('message') 
        ->setSize(4)
        ->setMargin(2)
        ->setOutfile($file)
        ->png();
 
        if( $newqrcode){
            $input['qrcode_path'] = $file;
 
    //         //update database
    $newqrcode =  QrCodeModel::where('id', $qrcode->id)
            ->update([
                'qrcode_path' => $input['qrcode_path']
            ]);
 
           
        }else{
            Flash::success('Qrcode saved successfully.');
        }
 
            Flash::error('Qrcode unsuccessfully saved.');
Arguments
"text"
array:1 [▶]

Shipment12's avatar

@VAN1310 - ```

GET Data empty POST Data _token "P5YEFVJooeUBGFai2TobaUuukcSPzDpKXxwotObe" user_id "1" website "faceboo.com" product_name "great" product_url "fried rice" company_name "wenick" callback_url "www.facebook/udediborfavour" amount "1200" status "1" Files empty Cookies remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d "eyJpdiI6Ik13cEpIaEZlalRjcFhXYUpWczBoaGc9PSIsInZhbHVlIjoiNWJ0MllReWRNQVA5bWQreHU1YjN1KzdtTmZ3MFlISWVsWHUrVDNcL2N2citSbTA3YW9YUEFtNDdPRlhYak9pXC96OXlMeCtnVDRpMCtm ▶" XSRF-TOKEN "eyJpdiI6IjNYWU1FZ1NyVUVtRXpOaUNkd0lNZ0E9PSIsInZhbHVlIjoiXC93RFo0STlNXC9UaGtrT3RwU3ZCKzlma0hEOStFcllRWXBYQ0diZTQ4YzhQaGRxdStCQ0pBeEZmdTlwYkx5K2VPIiwibWFjIjoiY2Jj ▶" laravel_session "eyJpdiI6ImNid0pqMkVmODlFYjBNd0hWUkZIQUE9PSIsInZhbHVlIjoieXFSTlZMSXVBMFRleWZsXC9zdTN6VnNpQU1yZHBtaDk0a0Ixb1FRcVJXam1tbW1RZDBOWVdRVnpZeU1uc1ZkcmciLCJtYWMiOiJkYTUz ▶" Session empty Server/Request Data DOCUMENT_ROOT "C:\xampp\htdoz\qrcode\public" REMOTE_ADDR "127.0.0.1" REMOTE_PORT "50774" SERVER_SOFTWARE "PHP 7.2.17 Development Server" SERVER_PROTOCOL "HTTP/1.1" SERVER_NAME "127.0.0.1" SERVER_PORT "8000" REQUEST_URI "/qrcodes" REQUEST_METHOD "POST" SCRIPT_NAME "/index.php" SCRIPT_FILENAME "C:\xampp\htdoz\qrcode\public\index.php" PATH_INFO "/qrcodes" PHP_SELF "/index.php/qrcodes" HTTP_HOST "127.0.0.1:8000" HTTP_CONNECTION "keep-alive" CONTENT_LENGTH "212" HTTP_CONTENT_LENGTH "212" HTTP_CACHE_CONTROL "max-age=0" HTTP_ORIGIN "http://127.0.0.1:8000" HTTP_UPGRADE_INSECURE_REQUESTS "1" CONTENT_TYPE "application/x-www-form-urlencoded" HTTP_CONTENT_TYPE "application/x-www-form-urlencoded" HTTP_USER_AGENT "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36" HTTP_ACCEPT "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3" HTTP_REFERER "http://127.0.0.1:8000/qrcodes/create" HTTP_ACCEPT_ENCODING "gzip, deflate, br" HTTP_ACCEPT_LANGUAGE "en-US,en;q=0.9" HTTP_COOKIE "remember_web_59ba36addc2b2f9401580f014c7f58ea4e30989d=eyJpdiI6Ik13cEpIaEZlalRjcFhXYUpWczBoaGc9PSIsInZhbHVlIjoiNWJ0MllReWRNQVA5bWQreHU1YjN1KzdtTmZ3MFlISWVsWHUrVD ▶" REQUEST_TIME_FLOAT 1556184289.6543 REQUEST_TIME 1556184289 Environment Variables empty Registered Handlers

  1. Whoops\Handler\PrettyPageHandler
DigiProduct's avatar

I don't know if you want a complex QR code with background images, or alternative colors ... but as long as all you want is a simple black on white QR Code ... and you don't need it to be larger than 547pixels by 547 pixels ... then you can do it all with one simple call to the Google API.

The old Google Chart Api was depreciated ... but the Infographics Api is still available

To create a QR Code with the text "QR Code for Laracasts" in a size of 500 pixels by 500 pixels you just need the folloing URI

https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=QR%20Code%20for%20Laracasts

You can view the documentation at

https://developers.google.com/chart/infographics/docs/overview

saeed410's avatar

use this package : simplesoftwareio/simple-qrcode and save image :

$fileNameCodeUnique = md5(time()); $qrcode = QrCode::size(512) ->format('svg') ->generate($request->code, base_path() . '/storage/app/public/qrproducts/qrcodes/' . $fileNameCodeUnique . '.svg');

1 like

Please or to participate in this conversation.