If you have a callback function that you need to re-use multiple times, you can assign it to a variable, and then re-use.
1$userCondition = function ($query) {2 $query->where('user_id', auth()->id());3};4 5// Get articles that have comments from this user6// And return only those comments from this user7$articles = Article::with(['comments' => $userCondition])8 ->whereHas('comments', $userCondition)9 ->get();