Laravel - Query Builder - Where Exists Clauses

The whereExists method allows you to write "where exists" SQL clauses. The whereExists method accepts a closure which will receive a query builder instance, allowing you to define the query that should be placed inside of the "exists" clause:

    $users = DB::table('users')
               ->whereExists(function ($query) {
                         ->whereColumn('orders.user_id', '');

The query above will produce the following SQL:

    select * from users
    where exists (
        select 1
        from orders
        where orders.user_id =