Laravel哪里有INNER JOIN?

时间:2017-09-27 22:16:00

标签: laravel laravel-5.4 laravel-5.5

我在Laravel中使用whereHas来构建查询:

})->whereHas('results', function ($query) use ($issued, $mode, $request) {

            if (($request->get("filter"))) {
                $query->where('issued', 0);
            }

        })->orderBy('created_at', 'desc')->paginate();

此问题返回零行,因为表results中现在有

 $query->where('issued', 0);

如何做到whereHas作为LEFT JOIN?现在它可以用作INNER JOIN

1 个答案:

答案 0 :(得分:4)

whereHas仅返回具有您正在寻找的关系的模型。如果您只想限制返回的Results,请尝试with

$models = Model::with(['results' => function($query){

    $query->where('issued', 0);

}])->get();