简体   繁体   中英

Object of class stdClass could not be converted to string laravel

im trying to use group by and sum in Laravel but this error code appear im new in Laravel and and this is my code

 $pemilik=DB::table("tb_simpanan")
                                     ->selectRaw('anggota_id,SUM(nominal_transaksi) as count')
                                     ->groupBy('anggota_id')
                                     ->get();  
                          $id1=1;
                          $data=DB::table('tb_master_bunga_simpanan')->where('id',$id1)->first();
                          $bunga=$data->persentase;
                          foreach($pemilik as $pem) {
                              $pem2[]=$pem->anggota_id;
                              $pem1[]=$bunga*$pem->count;     
                          }
                          $jumlah=sizeof($pem1);
                          $tanggal=date("Y-m-d H:i:s");
                          $test=3;
                        $idUser=Session::get('id');
                          $idUser1=DB::table('tb_anggota')->where('id',$idUser)->first();
                          for($i=1;$i<=$jumlah;$i++){
                              $data=[
                                    'anggota_id'=>$pem2[$i-1],
                                    'tanggal'=>$tanggal,
                                    'jenis_transaksi'=>$test,
                                    'nominal_transaksi'=>$pem1[$i-1],
                                    'id_user'=>$idUser1,
                               ];

                                DB::table('tb_simpanan')->insert($data);

enter image description here

Replace:

'id_user'=>$idUser1,

With

'id_user'=>$idUser1->id,

Or other attribute you may think suits better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM