根据关联表字段查询

$lists     = Orders::with(['goods:order_id,name'])
                ->whereHasIn('goods', function ($query) use ($goodsName) {
                    if ($goodsName) {
                        $query->where('name', 'like', '%' . $goodsName . '%');
                    }
                })
                ->select(['id', 'order_no'])
                ->paginate(10)
                ->toArray();

用到的扩展 dcat/laravel-wherehasin

posted @ 2021-09-18 17:02  CanyingV  阅读(52)  评论(0编辑  收藏  举报