0

I want to get all rows that have one unique column. The problem with my code is that it works only when I select just that one column, but in the end I need to have multiple columns.

$values= Model::select('id','value_first','gender_first','value_second','gender_second')->groupBy('value_first')->get();
Ali Jouadi
  • 133
  • 1
  • 2
  • 15
Beusebiu
  • 1,433
  • 4
  • 23
  • 68

2 Answers2

2

Here is Solution of Your Problem

$values= Model::select('id','value_first','gender_first','value_second','gender_second')->distinct('value_first')->get();
Naeem Ijaz
  • 805
  • 9
  • 17
1

As per Laravel Documentation you can use distinct method for the same

The distinct method allows you to force the query to return distinct results for e.g

$values= Model::select('id','value_first','gender_first','value_second','gender_second')->distinct('value_first')->get();

Reference: Laravel-> Database: Query Builder -> Selects

Sehdev
  • 5,486
  • 3
  • 11
  • 34