endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.46k stars 727 forks source link

Call to undefined method Endroid\QrCode\QrCode::getContentType() #310

Closed frzacode closed 3 years ago

frzacode commented 3 years ago

i made function like this to try the qr code out: function coba_qrcode() { $qrCode = new \Endroid\QrCode\QrCode('Life is too short to be generating QR codes'); header('Content-Type: ' . $qrCode->getContentType()); echo $qrCode->writeString(); }

but the result is Type: Error Message: Call to undefined method Endroid\QrCode\QrCode::getContentType()

endroid commented 3 years ago

Hi @frzacode what version are you using? 4.x does not have that method, 3.x does.

frzacode commented 3 years ago

i think the newest one because i installed it via composer just now

frzacode commented 3 years ago

if this method doesn't work with 4.x, what method should i use?

endroid commented 3 years ago

In the new version you should first create a result object and then you can use $result->getMimeType() to retrieve the type. The readme shows how you can generate a result object and call the method. Good luck ;)

x011 commented 2 years ago

why the examples on the readme don't work with the latest version? what's the point of having the examples then? Just google the error and check the amount of users that have the same problem. Something that should be simple is too complex for no reason.

endroid commented 2 years ago

Hi @x011 please let me know which example is incorrect and I will update it.

saranshquest commented 1 year ago

$qrCode = new QrCode($this->getImageData($image)); $decodedData = $qrCode->getText(); return $decodedData; when I use this code it gives me the error of Call to undefined method Endroid\QrCode\QrCode::getText() so how to fix this issue.

endroid commented 1 year ago

Hi @saranshquest the current version has no getText() method, see https://github.com/endroid/qr-code/blob/master/src/QrCode.php. You can check the readme for usage examples.

saranshquest commented 1 year ago

is it possible to scan the data from the qrcode and returns the all data which is present in the qrcode by the Endroid package in the laravel. public function scan(Request $request) { // Validate the uploaded file $request->validate([ 'qrCodeImage' => 'required|image', ]); // Get the uploaded file $qrCodeImage = $request->file('qrCodeImage'); $decodedData = $this->decodeQRCode($qrCodeImage); return response()->json(['data' => $decodedData]); } private function decodeQRCode($image) { $qrCode = new QrCode($this->getImageData($image)); $decodedData = $qrCode->getData(); return $decodedData; } private function getImageData($image) { $imagePath = $image->getRealPath(); $imageData = file_get_contents($imagePath);

    return $imageData;
}

So please help me to get the data from the qrcode through the endroid package in the laravel.

endroid commented 1 year ago

@saranshquest This library is for creating QR codes, not for reading. You could try the khanamiryan/qrcode-detector-decoder library for that purpose. Good luck!