  {"id":361,"date":"2022-09-24T16:03:55","date_gmt":"2022-09-24T16:03:55","guid":{"rendered":"https:\/\/247blogs.com\/wp\/2022\/09\/24\/laravel-9-tutorial-how-to-generate-various-qr-codes-in-laravel-9-application\/"},"modified":"2022-09-24T17:38:06","modified_gmt":"2022-09-24T17:38:06","slug":"laravel-9-tutorial-how-to-generate-various-qr-codes-in-laravel-9-application","status":"publish","type":"post","link":"https:\/\/247blogs.com\/wp\/laravel-9-tutorial-how-to-generate-various-qr-codes-in-laravel-9-application\/","title":{"rendered":"Laravel-9 Tutorial &#8211; How to Generate Various QR Codes in Laravel 9 Application"},"content":{"rendered":"<div id=\"\">\n<p>This guide will take you through all the necessary steps, which will tell you how to generate various QR codes in the Laravel 9 application using the simple QR code package.<\/p>\n<p>A simple QR code generator gives you the freedom to generate different types of QR Codes in the Laravel app. It gives a simple QrCode wrapper, which is easy to integrate into laravel, thanks to Bacon\/BaconQrCode.<\/p>\n<p>You can easily install in laravel using the Composer package; it requires package services to be registered in config\/app.php; after that, you can generate a variety of QR codes in laravel like simple QR codes, coloured QR codes even you can proliferate the QR codes in laravel with high-end customization.<\/p>\n<h2>Laravel 9 Simple QR Code Generator Tutorial with Example<\/h2>\n<ul>\n<li><strong>Step 1:<\/strong> Create Laravel Project<\/li>\n<li><strong>Step 2:<\/strong> Add Database Details<\/li>\n<li><strong>Step 3:<\/strong> Install QR Code Package<\/li>\n<li><strong>Step 4:<\/strong> Register QR Code Service<\/li>\n<li><strong>Step 5:<\/strong> Build Controller<\/li>\n<li><strong>Step 6:<\/strong> Add Route<\/li>\n<li><strong>Step 7:<\/strong> Generate QR Codes in Blade View<\/li>\n<li><strong>Step 8:<\/strong> Run Laravel App<\/li>\n<\/ul>\n<h2>Create Laravel Project<\/h2>\n<p>First, head over to the terminal and use the suggested command to install the new project. Don\u2019t forget to get inside the project folder.<\/p>\n<pre class=\"  language-bash\"><code class=\"  language-bash\">composer create-project --prefer-dist laravel\/laravel laravel-demo<\/code><\/pre>\n<pre class=\"  language-bash\"><code class=\"  language-bash\">cd laravel-demo<\/code><\/pre>\n<h2>Add Database Details<\/h2>\n<p>The <strong>.env<\/strong> config file helps you establish the database connection, make sure to add the database credentials in this file.<\/p>\n<pre class=\"  language-bash\" tabindex=\"0\"><code class=\"  language-bash\"><span class=\"token assign-left variable\">DB_CONNECTION<\/span><span class=\"token operator\">=<\/span>mysql\n<span class=\"token assign-left variable\">DB_HOST<\/span><span class=\"token operator\">=<\/span><span class=\"token number\">127.0<\/span>.0.1\n<span class=\"token assign-left variable\">DB_PORT<\/span><span class=\"token operator\">=<\/span><span class=\"token number\">3306<\/span>\n<span class=\"token assign-left variable\">DB_DATABASE<\/span><span class=\"token operator\">=<\/span>database_name\n<span class=\"token assign-left variable\">DB_USERNAME<\/span><span class=\"token operator\">=<\/span>database_user_name\n<span class=\"token assign-left variable\">DB_PASSWORD<\/span><span class=\"token operator\">=<\/span>database_password<\/code><\/pre>\n<p>If you are using MAMP local server in macOs; make sure to append UNIX_SOCKET and DB_SOCKET below database credentials in <strong>.env <\/strong>file.<\/p>\n<pre class=\"language-bash\" tabindex=\"0\"><code class=\"language-bash\"><span class=\"token assign-left variable\">UNIX_SOCKET<\/span><span class=\"token operator\">=<\/span>\/Applications\/MAMP\/tmp\/mysql\/mysql.sock\n<span class=\"token assign-left variable\">DB_SOCKET<\/span><span class=\"token operator\">=<\/span>\/Applications\/MAMP\/tmp\/mysql\/mysql.sock<\/code><\/pre>\n<h2>Install QR Code Package<\/h2>\n<p>Get into the command prompt, type the given command, and begin installing the <a href=\"https:\/\/www.simplesoftware.io\/#\/docs\/simple-qrcode\" rel=\"noopener\" target=\"_blank\">simplesoftwareio\/simple-qrcode<\/a> package; it profoundly helps create various kinds of QR codes in the laravel app.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\" language-bash\"><span class=\"token function\">composer<\/span> require simplesoftwareio\/simple-qrcode<\/code><\/pre>\n<h2>Register QR Code Service<\/h2>\n<p>You have to register the QR code services in to the <strong>config\/app.php<\/strong> file, so open the file and update the providers and alias array with the given below services.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\"  language-php\"><span class=\"token php language-php\"><span class=\"token delimiter important\"><?php<\/span>\n    <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">[<\/span>\n    <span class=\"token string single-quoted-string\">'providers'<\/span> <span class=\"token operator\">=><\/span> <span class=\"token punctuation\">[<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>                \n        <span class=\"token class-name class-name-fully-qualified static-context\">SimpleSoftwareIO<span class=\"token punctuation\"><\/span>QrCode<span class=\"token punctuation\"><\/span>QrCodeServiceProvider<\/span><span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span>\n    <span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span>\n    \n    <span class=\"token string single-quoted-string\">'aliases'<\/span> <span class=\"token operator\">=><\/span> <span class=\"token punctuation\">[<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>\n        <span class=\"token operator\">...<\/span><span class=\"token operator\">.<\/span>                \n        <span class=\"token string single-quoted-string\">'QrCode'<\/span> <span class=\"token operator\">=><\/span> <span class=\"token class-name class-name-fully-qualified static-context\">SimpleSoftwareIO<span class=\"token punctuation\"><\/span>QrCode<span class=\"token punctuation\"><\/span>Facades<span class=\"token punctuation\"><\/span>QrCode<\/span><span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span>\n    <span class=\"token punctuation\">]<\/span><\/span><\/code><\/pre>\n<h2>Build Controller<\/h2>\n<p>In laravel, all the business logic goes into the controller file, and we need a controller to create one by using the given command.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\" language-bash\">php artisan make:controller QrCodeController<\/code><\/pre>\n<p>Next, head over to <strong>resources\/views\/QrCodeController.blade.php<\/strong> and add the provided code.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\"  language-php\"><span class=\"token php language-php\"><span class=\"token delimiter important\"><?php<\/span>\n<span class=\"token keyword\">namespace<\/span> <span class=\"token package\">App<span class=\"token punctuation\"><\/span>Http<span class=\"token punctuation\"><\/span>Controllers<\/span><span class=\"token punctuation\">;<\/span>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Illuminate<span class=\"token punctuation\"><\/span>Http<span class=\"token punctuation\"><\/span>Request<\/span><span class=\"token punctuation\">;<\/span>\n<span class=\"token keyword\">class<\/span> <span class=\"token class-name-definition class-name\">QrCodeController<\/span> <span class=\"token keyword\">extends<\/span> <span class=\"token class-name\">Controller<\/span>\n<span class=\"token punctuation\">{<\/span>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">function<\/span> <span class=\"token function-definition function\">index<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span>\n    <span class=\"token punctuation\">{<\/span>\n      <span class=\"token keyword\">return<\/span> <span class=\"token function\">view<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">'qrcode'<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\n    <span class=\"token punctuation\">}<\/span>\n<span class=\"token punctuation\">}<\/span><\/span><\/code><\/pre>\n<h2>Add Route<\/h2>\n<p>In the controller we defined the function to load the view file, code in the controller is run by routes, so go ahead and define the new route in <strong>routes\/web.php<\/strong> file.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\"  language-php\"><span class=\"token php language-php\"><span class=\"token delimiter important\"><?php<\/span>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">Illuminate<span class=\"token punctuation\"><\/span>Support<span class=\"token punctuation\"><\/span>Facades<span class=\"token punctuation\"><\/span>Route<\/span><span class=\"token punctuation\">;<\/span>\n<span class=\"token keyword\">use<\/span> <span class=\"token package\">App<span class=\"token punctuation\"><\/span>Http<span class=\"token punctuation\"><\/span>Controllers<span class=\"token punctuation\"><\/span>QrCodeController<\/span><span class=\"token punctuation\">;<\/span>\n\n<span class=\"token class-name static-context\">Route<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">'\/generate-qrcode'<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token class-name static-context\">QrCodeController<\/span><span class=\"token operator\">::<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string single-quoted-string\">'index'<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/span><\/code><\/pre>\n<h2>Generate QR Codes in Blade View<\/h2>\n<p>We will show you how to use the view file and generate simple and colored QR Codes in laravel.<\/p>\n<p>Now, you are ready to set up a blade view file, hence create the blade view file within the views folder, after that add the provided code in the <strong>resources\/views\/qrcode.blade.php<\/strong> file.<\/p>\n<pre class=\" language-markup\" tabindex=\"0\"><code class=\" language-php\"><span class=\"token operator\"><<\/span><span class=\"token operator\">!<\/span><span class=\"token constant\">DOCTYPE<\/span> html<span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span>html<span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span>head<span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span>meta charset<span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"utf-8\"<\/span><span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span>title<span class=\"token operator\">><\/span>Laravel Generate <span class=\"token constant\">QR<\/span> Code Examples<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>title<span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span>meta name<span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"csrf-token\"<\/span> content<span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"{{ csrf_token() }}\"<\/span><span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span>link href<span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"https:\/\/cdn.jsdelivr.net\/npm\/bootstrap@5.0.2\/dist\/css\/bootstrap.min.css\"<\/span> rel<span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"stylesheet\"<\/span><span class=\"token operator\">\/<\/span><span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>head<span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span>body<span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"container mt-4\"<\/span><span class=\"token operator\">><\/span>\n        <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card\"<\/span><span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card-header\"<\/span><span class=\"token operator\">><\/span>\n                <span class=\"token operator\"><<\/span>h2<span class=\"token operator\">><\/span>Simple <span class=\"token constant\">QR<\/span> Code<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>h2<span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card-body\"<\/span><span class=\"token operator\">><\/span>\n                <span class=\"token punctuation\">{<\/span><span class=\"token operator\">!<\/span><span class=\"token operator\">!<\/span> <span class=\"token class-name static-context\">QrCode<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">300<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-><\/span><span class=\"token function\">generate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">'RemoteStack'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!<\/span><span class=\"token operator\">!<\/span><span class=\"token punctuation\">}<\/span>\n            <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n        <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n        <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card\"<\/span><span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card-header\"<\/span><span class=\"token operator\">><\/span>\n                <span class=\"token operator\"><<\/span>h2<span class=\"token operator\">><\/span>Color <span class=\"token constant\">QR<\/span> Code<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>h2<span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n            <span class=\"token operator\"><<\/span>div <span class=\"token keyword\">class<\/span><span class=\"token operator\">=<\/span><span class=\"token string double-quoted-string\">\"card-body\"<\/span><span class=\"token operator\">><\/span>\n                <span class=\"token punctuation\">{<\/span><span class=\"token operator\">!<\/span><span class=\"token operator\">!<\/span> <span class=\"token class-name static-context\">QrCode<\/span><span class=\"token operator\">::<\/span><span class=\"token function\">size<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">300<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-><\/span><span class=\"token function\">backgroundColor<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">255<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">90<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">-><\/span><span class=\"token function\">generate<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string single-quoted-string\">'RemoteStack'<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">!<\/span><span class=\"token operator\">!<\/span><span class=\"token punctuation\">}<\/span>\n            <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n        <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n    <span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>div<span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>body<span class=\"token operator\">><\/span>\n<span class=\"token operator\"><<\/span><span class=\"token operator\">\/<\/span>html<span class=\"token operator\">><\/span><\/code><\/pre>\n<h2>Start Application<\/h2>\n<p>Eventually, use the PHP artisan command to start the laravel server, also use the given url to view the app.<\/p>\n<pre class=\"  language-bash\"><code class=\"  language-bash\">php artisan serve<\/code><\/pre>\n<pre class=\"  language-bash\"><code class=\"  language-bash\">http:\/\/127.0.0.1:8000\/generate-qrcode<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.positronx.io\/wp-content\/uploads\/2021\/06\/14982-01.jpg\" alt=\"Create Different Barcodes in Laravel\" width=\"1000\" height=\"499\" class=\"alignnone size-full wp-image-14996\" srcset=\"https:\/\/www.positronx.io\/wp-content\/uploads\/2021\/06\/14982-01.jpg 1000w, https:\/\/www.positronx.io\/wp-content\/uploads\/2021\/06\/14982-01-768x383.jpg 768w, https:\/\/www.positronx.io\/wp-content\/uploads\/2021\/06\/14982-01-302x151.jpg 302w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\"><\/p>\n<h2>Conclusion<\/h2>\n<p>The laravel simple QR code tutorial, with an example, is ended. If you have understood every instruction that we shared so far, you will create QR codes in laravel without any problem.<\/p>\n<p>We explained the process of building basic QR codes; however, you can go further and create QR codes for MeCard, Geo Address, Website URL, Secured URL, E-mail Address, Phone Number, Text (SMS), and Wifi. We are sure you would love this package for its extended options.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This guide will take you through all the necessary steps, which will tell you how to generate various QR codes in the Laravel 9 application using the simple QR code [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":362,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,14],"tags":[],"class_list":["post-361","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-laravel","category-tutorial","clearfix"],"_links":{"self":[{"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/posts\/361","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/comments?post=361"}],"version-history":[{"count":1,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/posts\/361\/revisions"}],"predecessor-version":[{"id":692,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/posts\/361\/revisions\/692"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/media\/362"}],"wp:attachment":[{"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/media?parent=361"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/categories?post=361"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/247blogs.com\/wp\/wp-json\/wp\/v2\/tags?post=361"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}