You'll learn how to create a QR code. How to set up the qrcode package. Laravel qrcode configuration instructions. How to create a qr code in a function. displaying QR codes in blade templates. How to get it and decode the QR code.
Before you start this project, you need to make sure that you installed imagick already.
composer create-project --prefer-dist laravel/laravel qr_code_generator
or
laravel new qr_code_generator
composer require simplesoftwareio/simple-qrcode
Open config/app.php file and put the code like below:
'providers' => [
SimpleSoftwareIO\QrCode\QrCodeServiceProvider::class,
],
'aliases' => [
....
'QrCode' => SimpleSoftwareIO\QrCode\Facades\QrCode::class,
],
-
Syntax : The basic syntax is:
QrCode::size(100)->generate('Your value here!');
-
Set Size : We can set the size of the QR code image.
QrCode::size(300)->generate('Your value here!');
-
Color : We can also set background color.
QrCode::size(250)->backgroundColor(255,255,204)->generate('Your value here!');
php artisan make:Controller Qrcontroller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class Qrcontroller extends Controller
{
function generate()
{
return view('qrcode');
}
}
Route::get('generate',[Qrcontroller::class,'generate']);
php artisan make:view qrcode
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<title>Laravel QR Code Generator</title>
</head>
<body>
<div class="text-center" style="margin-top: 50px;">
<h3>Laravel QR Code Generator</h3>
<div>
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(300)->generate('Your value here!')) !!} ">
</div>
<div> <a href="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(300)->generate('Your value here!')) !!} " download>Downloads</a></div>
</div>
</body>
</html>