Level 63
You need to apply the condition to the relationship. You should also better use the where JSON clause.
User::with('foos')->whereRelation('foos', function ($query) {
$query->whereJsonContains('data->id', 123);
});
https://laravel.com/docs/9.x/eloquent-relationships#inline-relationship-existence-queries