I created a custom module and installed the endroid/qrcode library in my module using Composer. When I try to use that library, I get the following error.
Error: Class 'Endroid\QrCode\QrCode' not found in Drupal\shopexp\Plugin\Block\ShopExp->build() (line 25 of modules\custom\shopexp\src\Plugin\Block\ShopExp.php).
The code using the library is the following one.
namespace Drupal\shopexp\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Endroid\QrCode\QrCode;
class ShopExp extends BlockBase {
public function createpr() {
$qr = QrCode::create("https://site.com");
}
public function build() {
$qr = new QrCode();
return [
'#markup' => 'test msg',
];
}
}
The composer.json file used by the module is the following one.
{
"require": {
"endroid/qr-code": "^2.5"
}
}
The folder structure is the following one.