我想对我的数据表使用对象数组而不是查询,并且它不起作用,因为它不是来自查询集合。
我的数组就是这样
public function query(){
$santri = DataSantri::select('data_santri.*','id_vc')
->join('vc','data_santri.id_user','=','vc.id_user')
->whereIn('status_kegiatan',['ziyadah','mutqin','tahsin'])
->get();
foreach($santri as $row){
$pl = PaymentList::where('is_active',1)
->where('angkatan',$row->angkatan)
->where('payment_list.payment_time','bulanan')
->get();
$totalPl = DB::table('payment_list')
->where('is_active',1)
->where('angkatan',$row->angkatan)
->where('payment_list.payment_time','bulanan')
->sum('payment_price');
$pa = PaymentAddon::where('nis',$row->nis)->get();
$totalPa = DB::table('payment_addon')
->where('nis',$row->nis)
->sum('payment_price');
$data[] = array(
'nis' => $row->nis,
'id_vc' => $row->id_vc,
'nama_lengkap_santri' => $row->nama_lengkap_santri,
'jk' => $row->jk_santri,
'data_pembayaran_bulanan' => $pl,
'data_pembayaran_tambahan' => $pa,
'total' => $totalPl + $totalPa
);
}
$collect = collect($data);
return $this->applyScopes($collect);
}
它会返回这样的错误
Method Illuminate\Support\Collection::getQuery does not exist.
我该如何解决此错误?谢谢
答案 0 :(得分:0)
可以请您张贴问题。详细说明您如何使用Yajra数据表及所有数据。
数据表采用对象格式的数据,而您以数组格式提供数据,因此请将其更改为对象。
public function query(){
$santri = DataSantri::select('data_santri.*','id_vc')
->join('vc','data_santri.id_user','=','vc.id_user')
->whereIn('status_kegiatan',['ziyadah','mutqin','tahsin'])
->get();
$data = []; // initialize empty array
foreach($santri as $row){
$pl = PaymentList::where('is_active',1)
->where('angkatan',$row->angkatan)
->where('payment_list.payment_time','bulanan')
->get();
$totalPl = DB::table('payment_list')
->where('is_active',1)
->where('angkatan',$row->angkatan)
->where('payment_list.payment_time','bulanan')
->sum('payment_price');
$pa = PaymentAddon::where('nis',$row->nis)->get();
$totalPa = DB::table('payment_addon')
->where('nis',$row->nis)
->sum('payment_price');
$data[] = (object) array(
'nis' => $row->nis,
'id_vc' => $row->id_vc,
'nama_lengkap_santri' => $row->nama_lengkap_santri,
'jk' => $row->jk_santri,
'data_pembayaran_bulanan' => $pl,
'data_pembayaran_tambahan' => $pa,
'total' => $totalPl + $totalPa
);
}
return $this->applyScopes($data);
}
希望此帮助。如果这不起作用,请回复我,以便我告诉您使用 Yajra
的最佳数据表使用方式