Laravel雄辩地获得meta_key / meta_value

时间:2019-06-26 02:29:59

标签: wordpress laravel eloquent

我有一个使用元数据的WordPress表格。

我正试图从与details链接的details_metas中获取记录。

details_metas中,我需要通过比较meta_value和现在的meta_keyto_date的DateTime来过滤记录。

我该怎么做?我的代码返回了所有记录,但未按to_date进行过滤。

$builder->where(function ($q1) {
    $q1->whereIn('status_id', [3, 4]);
    $q1->orWhere(function ($q2) {
        $q2->where('status_id', 5);
        $q2->where(function ($q3) {
            $q3->whereHas('certificates', function ($q4) {
                $q4->where('expiry_date', '>=', Carbon::now()->toDateTimeString());
            });
            $q3->orWhereHas('details_meta', function ($q4) {
                $q4->with([
                    'details_meta' => function ($query) {
                        $query->where('*.meta_key', 'to_date');
                        $query->where('*.meta_value', '<=', Carbon::now()->toDateTimeString());
                    }
                ]);
            });
        });
    });
});

0 个答案:

没有答案