I want to fetch each id of certificate number

  Sat 18 / 03 / 2023

  Posted by: OG Designs

Category : Laravel

Tags : laravel , php , php laravel , web , backend , deployment

Post Thumbnail
Description

I am trying to show (display) each id certificate number, but it is fetching only first id certificate number from db table instead of fetching each id's certificate number


View Code
                        <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use setasign\Fpdi\Fpdi;
// use App\Http\Requests\CertificatesRequest;
use App\Models\Certificate;
use Illuminate\Support\Facades\Storage; 
use Illuminate\Support\Facades\Auth;
class FillPDFController extends Controller


{
    public function process($id)

    {
       
        $certificate = Certificate::find($id);
    
    //      if (!$certificate->photo) {
    //          $qrCode = \QrCode::format('png')
    //              ->size(200)->generate(route('certificate.show', $certificate->id));

    //          $output_file = '/img/qr-code/' . time() . '.png';

    // Storage::disk('public')->put($output_file, $qrCode);
    //          $certificate->photo = $output_file;
    //          $certificate->save();
    //         }

//$nama = $request->post('nama'); 
       
        // $nama = "TERHIDE TYAVYAR JNR";
        $outputfile = public_path().'dcc.pdf';
        $this->fillPDF(public_path().'/master/dcc.pdf',$outputfile,$certificate->name);
        //$this->fillPDF(public_path().'master/dcc.pdf', $outputfile, $certificate->name, $certificate->photo);
        return response()->file($outputfile);
    }

    public function fillPDF($file,$outputfile,$nama)
    {
        $certificates= Certificate::all();
        foreach($certificates as $certificate){
        $fpdi = new FPDI;
        $fpdi->setSourceFile($file);
        $template = $fpdi->importPage(1);
        $size = $fpdi->getTemplateSize($template);
        $fpdi->AddPage($size['orientation'],array($size['width'],$size['height']));
        $fpdi->useTemplate($template);
        $top =98;
        $right = 105;
        $nama = $nama;
        $fpdi->SetFont("helvetica","",25);
        $fpdi->SetTextColor(25,26,25);
        $fpdi->Text($right,$top,$nama);
        $fpdi->ln();
        // $fpdi->Cell(0,10,"Reg Code",'',0,0,'C');
        $top =30;
        $right = 186;
        $fpdi->SetFont("helvetica","",12);
        $fpdi->Text($right,$top,$certificate->certificate_num);
        
        
       //get the QRcode PNG  u generated
        $qrImage=storage_path('/app/public/img/qr-code/1676318628.png');
      

        // insert image at position x,y,w,h 
        $fpdi->Image($qrImage,234,55,36,30);
        //   Storage::disk('public')->put($output_file, $image);   
        return $fpdi->Output($outputfile,'F');
    }
        
    }

    }
                
  Answered by CDL

In the above code, you are getting dynamic id using the $id parameter in the function and finding the record in the database which is totally fine. If you are getting only the first post so make sure that you are passing a unique id or not.

How to check the id?

Simply add this line to the start process function

public function process($id)

{

  dd($id);

}
it will print the user id in the web browser, if it's returning the same id even though you are performing a different option, it means that you are not passing this id correctly from the frontend.

Solved
  Comment   Share
0 Likes   1 Comment


comment-author
OG Designs Author

I have solved the problem



Reply


commented 1 year ago
comment-author
Hadayat Niazi Super Admin

Sounds good, can you please share the solution with us, so we will mark your comment as "best answer". Thank you