Laravel 二维码:endroid/QrCode,如何使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23473336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel QR Codes: endroid/QrCode, how to use it?
提问by LoveAndHappiness
I would like to use a QR-Code generator with my Laravel 4.1 application. I am currently choosing between https://github.com/endroid/QrCodeand https://github.com/endroid/EndroidQrCodeBundle. To be honest though, neither appear to have any documentation on how to use them.
我想在我的 Laravel 4.1 应用程序中使用二维码生成器。我目前正在https://github.com/endroid/QrCode和https://github.com/endroid/EndroidQrCodeBundle之间进行选择。老实说,两者似乎都没有关于如何使用它们的任何文档。
Can someone describe the first steps, after an successful composer installation, on how to produce QR codes?
有人可以描述在成功安装 Composer 后如何生成二维码的第一步吗?
Thank you in advance for every step. I know this is kind of a generic question, but I am kind of new to Laravel.
预先感谢您的每一步。我知道这是一个通用的问题,但我对 Laravel 有点陌生。
回答by Emeka Mbah
I don't know if this late response but for anyone who is having this challenge, this is fairly simple;
我不知道这是否是迟到的回应,但对于任何遇到此挑战的人来说,这相当简单;
<?php namespace App\Http\Controllers
use Endroid\QrCode\QrCode;
class ImageController extends Controller{
public function _construct(QrCode $qrCode){
$this->qrCode = $qrCode;
}
public function makeQrCode($text){
return $this->qrCode
->setText($text)
->setSize(300)
->setPadding(10)
->setErrorCorrection('high')
->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))
->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0))
->setLabel('My label')
->setLabelFontSize(16)
->render();
}
}
You route may look like this:
您的路线可能如下所示:
Route::get('image/qrcode/{$text}',[
'uses' => 'ImageController@makeQrCode',
'as' => 'qrcode'
]);
So later you can do this in your blade:
因此,稍后您可以在刀片中执行此操作:
<img src="{!! route('qrcode',['text'=>'Hello world']) !!}" alt="QR Code">