Laravel add condition on relationships
$response = User::with(['roles' => function ($query) {
$query->whereIn('id', [1, 2, 3]);
$query->orWhere('role_name', 'like', '%{$query}%');
}])->where('full_name', 'LIKE', "%{$query}%")->paginate(10);
click for more Laravel codes read about laravel relationships