get records using model object with count disctinct in laravel code example Example: eloquent get distinct $ad->getcodes()->distinct('pid')->count('pid');