1. Go to this page and download the library: Download sghimire/mobile-scanner library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sghimire / mobile-scanner example snippets
Scanner::scan()->gallery(false)->scan();
use Sandip\Scanner\Native\Facades\Scanner;
// Scan a single QR code with defaults
Scanner::scan()->scan();
// Fully configured
Scanner::scan()
->id('ticket-scanner') // correlate this scan with its events
->prompt('Scan your ticket') // text shown above the camera viewfinder
->formats(['qr', 'ean13']) // one or more barcode formats to detect
->continuous() // keep scanning after each match
->scan();
use Sandip\Scanner\Native\Facades\Scanner;
Scanner::stop(); // stop whatever scanner is open
Scanner::stop('ticket-scanner'); // stop a specific session by id
use Sandip\Scanner\Native\Events\Scanner\CodeScanned;
use Sandip\Scanner\Native\Events\Scanner\Cancelled;
use Illuminate\Support\Facades\Event;
Event::listen(function (CodeScanned $event) {
$event->data; // string — the decoded value
$event->format; // string — which format matched, e.g. "qr"
$event->id; // ?string — matches the id you passed to ->id(), if any
});
Event::listen(function (Cancelled $event) {
$event->reason; // ?string — e.g. "user_cancelled", "stopped_by_app", "timeout", "camera_error"
$event->id; // ?string
});
use Livewire\Component;
use Sandip\Scanner\Native\Attributes\OnNative;
use Sandip\Scanner\Native\Events\Scanner\CodeScanned;
use Sandip\Scanner\Native\Events\Scanner\Cancelled;
use Sandip\Scanner\Native\Facades\Scanner;
class TicketScanner extends Component
{
public ?string $result = null;
public function startScan(): void
{
Scanner::scan()->id('ticket-scanner')->prompt('Scan your ticket')->scan();
}
#[OnNative(CodeScanned::class)]
public function onCodeScanned(string $data, string $format, ?string $id): void
{
$this->result = $data;
}
#[OnNative(Cancelled::class)]
public function onCancelled(?string $reason, ?string $id): void
{
// handle the user closing the scanner
}
}