get all data from a distinct id in laravel eloquent code example Example: eloquent get distinct $ad->getcodes()->distinct('pid')->count('pid');