Count entries of 2 different tables grouped by date and combine results in Laravel 4.2

I would like to know how to count the number of entries of two different tables grouped by date and then combine the 2 result sets into 1 structure in Laravel 4.2?

Table1 (riders)

|  id  |  rider  |  created_at           |
|  1   |  james  |  2017-08-27 03:01:22  |
|  2   |  clara  |  2017-05-27 06:32:33  |
|  3   |  john   |  2017-04-27 09:54:32  |
|  4   |  ken    |  2017-04-27 09:54:32  |

Table2 (drivers)

|  id  |  driver  |  created_at           |
|  1   |  Karlie  |  2017-08-27 03:01:22  |
|  2   |  Doe     |  2017-03-27 06:32:33  |
|  3   |  Mike    |  2017-02-27 09:54:32  |

I would like to make an output like these:

|  created_at  |  rider entries  |  driver entries  |
|  2017-02-27  |  0              |  1               |
|  2017-03-27  |  0              |  1               |
|  2017-04-27  |  2              |  0               |
|  2017-05-27  |  1              |  0               |
|  2017-08-27  |  1              |  1               |

You can use the Query Builder to get the counts from each table (see documentation here https://laravel.com/docs/4.2/queries) but to combine them you will have to loop.

Your code may look something like this:

// Get the counts for riders table
$riders = DB::table('Table1')
                ->groupBy('created_at')
                ->count();

// Get the counts for drivers table
$drivers = DB::table('Table2')
                ->groupBy('created_at')
                ->count();

// An associative array to hold our final result
$combined = [];

// Loop over riders, adding them to the combined array
foreach( $riders as $rider ){
    // Array keys have to start with a letter
    $key = 'd' . $rider->created_at->format('Y-m-d');
    $combined[$key]['created_at'] = $rider->created_at->format('Y-m-d');
    $combined[$key]['rider_entries'] = $rider->count;
}

// Loop over drivers, adding them to the combined array
foreach( $drivers as $driver ){
    $key = 'd' . $driver->created_at->format('Y-m-d');
    $combined[$key]['created_at'] = $driver->created_at->format('Y-m-d');
    $combined[$key]['driver_entries'] = $driver->count;
}

// Finally, iterate over the result, filling in zero values
foreach( $combined as $c ){
    if( !isSet($c['rider_entries']) ){
        $c['rider_entries'] = 0;
    }
    if( !isSet($c['driver_entries']) ){
        $c['driver_entries'] = 0;
    }
}

dd( $combined );

Note: I have not tested this code but I hope this helps gives you an idea of how best to do it.