Good day everyone! I'm pretty new to Laravel, and I've been doing a little project with QrCode for about a month.
So my question is: "How do I store a generated QR code into the database in Laravel?"
I have created a function which will create random strings (which act as a unique ID for my assets) and converted into QR code. My next action would be to place the QR code image into my database. I've been following a lot of Laravel tutorial but it's only on uploading image not saving an automatically generated image.
I did save the QR code image inside public folder but it will get overwritten every time I create a new QR code.
This is how I create random strings and convert them into the QR Code and save them
$rs = md5(time(). mt_rand(1,100000));
$assets = Input::all();
$assets = new Assets;
$assets->assets_name = Input::get('assets_name');
$assets->assets_random_string = $rs;
$assets->save();
$file = public_path('qr.png');
\QRCode::text($rs)->setOutFile($file)->png();
return redirect('assets/list')->with('assets', $assets)
Please do comment if I've done anything wrong inside my existing so I can improve my code. And let me know if you need anything from my project.
Thank you so much!
Any help is welcomed!
Save to content of the QR Code in the DB and generate the QR Code on demand, that should be the best way.
The correct way and most optimized way is that you save your file path to qr.png in you database. And once you need to show your QR code you simply pull out the path from you database and attaches it to an HTML img tag.