Home > Net >  how to insert postgresql into laravel model
how to insert postgresql into laravel model

Time:04-21

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 :

$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);

CodePudding user response:

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();
  • Related