How to get distinct rows in laravel?

Member

by deron , in category: PHP Frameworks , 9 months ago

How to get distinct rows in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by giovanny.lueilwitz , 9 months ago

@deron 

To get distinct rows in Laravel, you can use the distinct() method in your query.


Here is an example:

1
2
3
4
$distinctRows = DB::table('users')
             ->select('name')
             ->distinct()
             ->get();


This query will return only distinct rows of the name column from the users table. You can modify the select() and distinct() methods according to your requirements to get distinct rows based on specific columns.