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

CookieMonster's avatar

laravel- Scan QR code for customer to verify

I implement a QR (simple QR package from laravel) to my invoice for an e-commerce website. When the customer sees the invoice with the QR attached to it, he or she can scan it with the smartphone and it will bring them to a page that shows them the order details,etc and they can click ok to verify it.

My QR on my invoice (dompdf) is as below:

<img style="float:right; margin-bottom:10px;" src="data:images/png;base64, {{ base64_encode(QrCode::format('png')->size(100)->generate('no-idea')) }} ">

Now, the problem is I do not think the customer needs to log in to verify the QR and I do not know how to make it unique. I was thinking once generated, it will bring them to a page , where I need to create a blade template and pass in those order details?

Please advice as I have never done this before.

0 likes
10 replies
Tray2's avatar

There are several ways to do that.

One is to hash let's say the users email and order number

$hash = Hash::make($user->email + $this->orderno);

Or you can use uuid to generate a unique key

$id = Str::uuid();

Then you can use some endpoint like

Route:.get('orders/confirm/{order}/{hash}', 'OrderConfirmationController@show');
1 like
CookieMonster's avatar

Let's say I go with option 1: hash,

In my QR code, where do I link the customer to when he scans?

CookieMonster's avatar

Can I just use hash a random number and not user email or order number?

Tray2's avatar

Yes you can do that or just use the str::uuid() helper which generates a random unique identifier.

1 like
CookieMonster's avatar

I did it this way. Take a look:

web.php

//Show order confirmation when customer scan QR (invoice)
Route::get('/orders/confirm/{order}/{hash}', 'OrderController@show');

order controller:

public function show($id)
    {
        $hash = Hash::make($user->email + $this->orderno);
        return view('qr.confirm-order');
    }

Though not sure how do I retrieve user and order no.

Tray2's avatar

You need to create the hash when the order is inserted into your orders table.

CookieMonster's avatar

The hash is to prevent customer from accessing orders that do not belong to them?

Tray2's avatar

Yes.

An order number might look something like 5155255 and then the hash is to prevent anyone from just changing the order number manually in the url.

Snapey's avatar

You need to make sure that the hash is suitable for encoding in a URL (only uses url safe characters)

Or, use a long random token, or signed URLs

Please or to participate in this conversation.