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 insert postgresql into laravel model

I have a postgresql code like this and it runs correctly but I’m confused to enter the laravel model

postgresql :

select * from anggota a where id_parpol = 4 and a.nik in ('2816742691102816','8939799808489659','4757527446829790') or a.no_kta in ('2816742691102816','8939799808489659','4757527446829790')

anggotaContoller :

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

$aa = "2816742691102816,8939799808489659,4757527446829790";
$bb = explode(",", $aa);
$model = Anggota::where('id_parpol', Auth::user()->id_org)->whereIn('nik', $bb)->whereIn('no_kta', $bb)->get();
dd($model);

>Solution :

You can use closure based grouping of queries

$model = Anggota::where('id_parpol', Auth::user()->id_org)
   ->where(function($query) use($bb){
        $query->whereIn('nik', $bb)
               ->orWhereIn('no_kta', $bb);
})->get();
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