select distinct laravel repository query code example Example: eloquent get distinct $ad->getcodes()->distinct('pid')->count('pid');