Fixed issue using whereHas with HasManyThrough Relationship

Originally created this PR towards master branch and was asked to create it for the 4.1 branch.

Reference: https://github.com/laravel/framework/pull/3561