i try to create qr viewer which is collecting text from databases, and show it as a Qr code. but it’s always get me an error where qr_codes not defined
this my controller code
<?php
namespace AppHttpControllers;
use IlluminateSupportFacadesDB;
use IlluminateHttpRequest;
use AppHttpControllersController;
use ApphttpRequests;
class QrCodeController extends Controller{
public function index(){
$qr_codes = DB::select('select * from qr_code');
return view ('QRcodeviewer',['qr_code'=>$qr_codes]);
}
}
and here my blade view code
@extends('layouts.dashboard')
@section('content')
<div class="container mt-4">
<div class="card">
<div class="card-header">
<h2>QR Absen</h2>
</div>
<div class="card-body">
{{ QrCode::size(300)->generate(Route('QRCodeviewer',$qr_codes->uuid)) }}
</div>
</div>
</div>
@endsection
and this my routes
Route::get('QRcodeviewer','QrCodeController@index');
[error message]
https://i.stack.imgur.com/YvKJT.png
2
Answers
This is because of your spelling error.
In your controller you set qr_code without s
but in view blade you try to access using $qr_codes,
try change to
In your controller:
In your view: