$users = User::whereHas('comments', function($query) { $query->where('body', 'LIKE', '%important%'); })->get();
use Carbon\Carbon; $users = User::whereHas('posts', function($query) use ($date) { $date = Carbon::now()->subMonth(); $query->where('created_at', '>=', $date); })->withCount('posts')->having('posts_count', '>', 10)->get();This code uses the `whereHas` method to find users who have related posts. The anonymous function adds a filter to the query to find posts created in the last month. The `withCount` method adds a count of related posts to the result, and the `having` method filters based on that count to find users with more than 10 posts. The `whereHas` method is part of the Eloquent ORM, a package within Laravel for working with databases.