Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add validate data search

I am using laravel for this project, i’m newbie at laravel then i want to add validate data if there is true then go to pdf blade, unless the data is false or wrong (i don’t know what is it call so i named it True and False, but i hope you understand what i mean)

there is code in controller method search pdf

$id = $request->id;
    $date = $request->date;

    $pegawai = DB::table('pegawais')
            ->where('id', $id)
            ->whereDate('date', $date)
            ->get();

    $pdf = PDF::loadview('pegawai_pdf', [
        'pegawai'=>$pegawai
    ]);

    return $pdf->stream();

and this is the output blade when i searched the data is true or exist
here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

and this is the output blade when i searched but the data is false or not found data exist

here

fyi the data are fake data from seeder,

>Solution :

From your example, I will assume that you want to check if there is a result or not in $pegawai right? Then just count it.

if (count($pegawai) > 0) {
    // show your pdf output here
} else {
    // there is no data, do something here
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading