$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();
}
$results = User::with([
'country' => function ($query) {
$query->select('id','name');
},'posts' => function ($query) {
$query->select('id','user_id','title');
},'posts.attachments' => function ($query) {
$query->select('id','post_id','type');
}])->get(['id','country_id','name']);