I have a query scope from a L5.1 app that is not working on L5.7. The scope adds a simple join with a DB::raw statement like so:

```php
    public function scopeLatest($query)
    {
        return $query->join(DB::raw('(SELECT patient_id, MAX(created_at) created_at FROM referral_reports GROUP BY patient_id) r2'), function ($join) {
                            $join->on('referral_reports.patient_id', '=', 'r2.patient_id');
                            $join->on('referral_reports.created_at', '=', 'r2.created_at');
                            });
    }

```

Using this scope on L5.1 worked great, but in 5.7, the entire join is omitted from the query and no error is thrown. I had to use DB::enableQueryLog() on both apps to see that the resulting queries were different.

Any idea why this isn't working in 5.7?

Here is an example of using this scope via a static method on the model:

```
        $entries = self::inStudies($studies)
                       ->calltime($startDate, $endDate)
                       ->latest()
                       ->omitdeleted()
                       ->get();

```

inStudies, calltime, latest, omitdeleted are all query scopes.