laravel model example to retrieve distinct records from db Example: eloquent get distinct $ad->getcodes()->distinct('pid')->count('pid');