skip to Main Content

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


  1. This is because of your spelling error.

    In your controller you set qr_code without s

    return view ('QRcodeviewer',['qr_code'=>$qr_codes]);
    

    but in view blade you try to access using $qr_codes,
    try change to

    {{ QrCode::size(300)->generate(Route('QRCodeviewer',$qr_code->uuid)) }}
    
    Login or Signup to reply.
  2. In your controller:

    $qr_code = DB::table('qr_code')->first();
    return view ('QRcodeviewer',['qr_code'=> $qr_code]);
    

    In your view:

     {{ QrCode::size(300)->generate(Route('QRCodeviewer',$qr_code->uuid)) }}
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search