3

I would like to use a QR-Code generator with my Laravel 4.1 application. I am currently choosing between https://github.com/endroid/QrCode and https://github.com/endroid/EndroidQrCodeBundle. To be honest though, neither appear to have any documentation on how to use them.

Can someone describe the first steps, after an successful composer installation, on how to produce QR codes?

Thank you in advance for every step. I know this is kind of a generic question, but I am kind of new to Laravel.

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64
LoveAndHappiness
  • 9,735
  • 21
  • 72
  • 106
  • What in the documentation for endroid is giving you trouble? BTW, bundles are no longer used in Laravel 4. – ceejayoz May 05 '14 at 13:19
  • I know, I am installing them through composer. To answer your question, everything gives me trouble. For other bundles, I have to write often things into the app/config.php file (aliases or ServiceProvider), and I don't at all how to start on this. – LoveAndHappiness May 05 '14 at 13:54
  • You shouldn't need to add an alias or service provider. Just use the example code as a route's return. `Route::get('test', function() { $qrCode = new Endroid\QrCode\QrCode(); $qrCode->setText("Life is too short to be generating QR codes"); $qrCode->setSize(300); $qrCode->setPadding(10); return $qrCode->render(); }` – ceejayoz May 05 '14 at 14:47
  • I have followed the code and the result is a garbage. – ruelluna Nov 11 '14 at 03:58

1 Answers1

4

I don't know if this late response but for anyone who is having this challenge, this is fairly simple;

<?php namespace App\Http\Controllers
use Endroid\QrCode\QrCode;
class ImageController extends Controller{

    public function _construct(QrCode $qrCode){
        $this->qrCode = $qrCode;
    }

    public function makeQrCode($text){
       return $this->qrCode
       ->setText($text)
       ->setSize(300)
       ->setPadding(10)
       ->setErrorCorrection('high')
       ->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
       ->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
       ->setLabel('My label')
       ->setLabelFontSize(16)
       ->render();
    }
}

You route may look like this:

Route::get('image/qrcode/{$text}',[
  'uses' => 'ImageController@makeQrCode',
  'as'   => 'qrcode'
]);

So later you can do this in your blade:

<img src="{!! route('qrcode',['text'=>'Hello world']) !!}" alt="QR Code">
Emeka Mbah
  • 16,745
  • 10
  • 77
  • 96
  • Thanks for your solution. If you know, why would you prefer a php (serverside) solution, instead of letting javascript do the qr code generation? Any pro or contra right now in your mind? – LoveAndHappiness Nov 24 '15 at 03:31
  • 1
    Well, I arrived at your question because I was looking for a package that will be able to generate qrcode so I can store it my database. I prefer to use serverside qrcode generator in my own scenario because my app is an API which must generates a serials of unqiue PIN number s(14 digits) and generate qrcode fo each PIN number. I am using this. https://github.com/SimpleSoftwareIO/simple-qrcode – Emeka Mbah Nov 24 '15 at 07:19
  • Bro Its working very well. But i want to generate qrcode for a big string, around 4000 character. in this case this will failed. How can i solve this issue. – shijinmon Pallikal Jun 29 '17 at 13:51