ManyToMany Eloquent Laravel query issue with whereHas

Solution:

It is like a 5.4 issue. (https://github.com/laravel/framework/issues/26936) You should try to upgrade from 5.4 to 5.5