首页 > 解决方案 > laravel 关系按数据分组

问题描述

如果不为空,如何通过 qrcode 和 sum price 选择此关系计数中的数据?

$wajibRetribusis = 
    WajibRetribusi::with(['subDistrict' => function ($q) use ($month, $year) {
                            $q->select('name', 'id');
                    }, 'payments' => function ($q) use ($month, $year) {
                            $q->whereMonth('payments.last_paid', $month);
                            $q->whereYear('payments.last_paid', $year);
                            $q->select('id', 'price', 'qr_code', 'category_id', 'last_paid');
                    }, 'category:id,price'])
                ->select('sub_district_id', 'qr_code', 'category_id')
                ->get();

标签: laravelrelation

解决方案


推荐阅读