📜  laravel 急切加载 where 子句 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:52.150000             🧑  作者: Mango

代码示例1
$query = ""    

if ($request->has('country'){
$query = Post::with("country")->whereHas("country",function($q) use($request){
    $q->where("name","=",$request->country);
})->get()
}else{
    $query = Post::with("country")->get();
}