all query working in controller but not distinct code example Example: eloquent get distinct $ad->getcodes()->distinct('pid')->count('pid');