-1

我想对我的数据表使用对象数组而不是查询,但它不起作用,因为它不是来自查询集合。

我的数组就像这样

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.

我该如何解决这个错误?谢谢你

4

1 回答 1

0

你能发个问题吗。详细意味着您如何使用 Yajra 数据表和所有内容。

Datatable 以对象格式获取数据,并且您以数组格式提供,因此请将其更改为对象。

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使用数据表的最佳方法

于 2019-02-22T05:08:00.003 回答