Skip to content

Latest commit

 

History

History
261 lines (190 loc) · 7.39 KB

README.md

File metadata and controls

261 lines (190 loc) · 7.39 KB

Laravel Package for QR Code generator in easy way.

A QR code (quick response code) is a type of 2D bar code that is used to provide easy access to information through a smartphone. In this process, known as mobile tagging, the smartphone's owner points the phone at a QR code and opens a barcode reader app which works in conjunction with the phone's camera.

Installation

Inside your project root directory, open your terminal

composer require peal/qrcode-generator

Composer will automatically download all dependencies.

For Laravel

After complete the installation, open your app.php from config folder, paste below line inside providers array

peal\qrcodegenerator\QrServiceProvider::class,

For Facade support, paste below line inside aliases array

'QR' => peal\qrcodegenerator\Facades\QR::class,

Then run this command

php artisan vendor:publish --provider="peal\qrcodegenerator\QrServiceProvider"

After vendor published check your config folder qr-config.php is created.

/*
 * QR api url
 * 
 */

return [
    'qrapi'  => 'https://chart.googleapis.com/chart?',
];

SINGLE QR CODE USAGES

 //Using Facades
 
try {
        $qrcontent = QR::qrFactory()
                ->email("moinuddin7@gmail.com")
                ->phone("01716187302")
                ->url("https://moinshareidea.wordpress.com/")
                ->text("position:","Lead Developer at GrubDealz Inc.")
                ->QrCode(200);

        echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';

} catch(Exception $e) {

    return $e->getMessage();

}

//Using service container

try {
        
        $qr = App::make('QR');

        $qrcontent = $qr->qrFactory()
                ->email("moinuddin7@gmail.com")
                ->phone("01716187302")
                ->text("website:","https://moinshareidea.wordpress.com/")
                ->text("position:","Lead Developer at GrubDealz Inc.")
                ->QrCode(200);

        echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';
} catch(Exception $e) {

    return $e->getMessage();

}

//Using core PHP

try {
        
        //Without Laravel, can be usable any php or php framework 
        
        $qr = new \peal\qrcodegenerator\Server\QrServer();
        
        $qrcontent = $qr->qrFactory()
                ->email("moinuddin7@gmail.com")
                ->phone("01716187302")
                ->text("website:","https://moinshareidea.wordpress.com/")
                ->text("position:","Lead Developer at GrubDealz Inc.")
                ->QrCode(200);
    
        echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';

} catch(Exception $e) {

    return $e->getMessage();

}

Multiple QR code using Facades

    
    //in your controller contruct method
    $qr = App::make('QR');
    
    try {
            $qrcodes = [
                [
                    'email' => 'moinuddin7@gmail.com',
                    'phone' => '01716187302',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Lead Developer at GrubDealz Inc.',
                ],
                [
                    'email' => 'moinuddinbca7@gmail.com',
                    'phone' => '01716187332',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Software engineer at GrubDealz Inc.',
                ],
                [
                    'email' => 'arifinbca@gmail.com',
                    'phone' => '01716187392',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Business development officer at BCA Bangladesh.',
                ],
            ];

            foreach($qrcodes as $qrcode) {
                    $qrcontent = $qr->qrFactory()
                        ->email($qrcode['email'])
                        ->phone($qrcode['phone'])
                        ->url($qrcode['url'])
                        ->text('',$qrcode['position'])
                        ->QrCode(200);

                    echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';
            }

        } catch(Exception $e) {

            return $e->getMessage();

        }
        
        

Multiple QR Code using Core PHP

use peal\qrcodegenerator\Server\QrServer;
$qr = new QrServer();
    
    try {
            $qrcodes = [
                [
                    'email' => 'moinuddin7@gmail.com',
                    'phone' => '01716187302',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Lead Developer at GrubDealz Inc.',
                ],
                [
                    'email' => 'moinuddinbca7@gmail.com',
                    'phone' => '01716187332',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Software engineer at GrubDealz Inc.',
                ],
                [
                    'email' => 'arifinbca@gmail.com',
                    'phone' => '01716187392',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Business development officer at BCA Bangladesh.',
                ],
            ];

            foreach($qrcodes as $qrcode) {
                    $qrcontent = $qr->qrFactory()
                        ->email($qrcode['email'])
                        ->phone($qrcode['phone'])
                        ->url($qrcode['url'])
                        ->text('',$qrcode['position'])
                        ->QrCode(200);

                    echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';
            }

        } catch(Exception $e) {

            return $e->getMessage();

        }

Multiple QR code using Facades

    use peal\qrcodegenerator\Facades\QR;
    
    try {
            $qrcodes = [
                [
                    'email' => 'moinuddin7@gmail.com',
                    'phone' => '01716187302',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Lead Developer at GrubDealz Inc.',
                ],
                [
                    'email' => 'moinuddinbca7@gmail.com',
                    'phone' => '01716187332',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Software engineer at GrubDealz Inc.',
                ],
                [
                    'email' => 'arifinbca@gmail.com',
                    'phone' => '01716187392',
                    'url' => 'https://moinshareidea.wordpress.com/',
                    'position' => 'Business development officer at BCA Bangladesh.',
                ],
            ];

            foreach($qrcodes as $qrcode) {
                    $qrcontent = QR::qrFactory()
                        ->email($qrcode['email'])
                        ->phone($qrcode['phone'])
                        ->url($qrcode['url'])
                        ->text('',$qrcode['position'])
                        ->QrCode(200);

                    echo '<p class="center"><img src="' . $qrcontent . '" alt="QR Code" /></p>';
            }

        } catch(Exception $e) {

            return $e->getMessage();

        }

Author

Mohammed Minuddin(Peal)