Level 88
This is the example from the documentation:
DB::table('users')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();
Documentation: https://laravel.com/docs/5.6/queries#where-clauses
However I think you can do something like this
$bills = Bill::upcoming()->where('amount', function ($query) {
$query->selectRaw('SUM(deposits.amount)')
->from(with(new Deposit)->getTable())
->where('bill_id', '=', 'bills.id')
})->get();
Note: I didn't test this, but I think it should work! At least I hope I put you in the right direction here!