here is my code –
$list = Plot::active()
->whereNotNull('user_id')
->distinct('user_id')
->with('user')
->paginate(10);
but here "distinct(‘user_id’)" not working. I want only unique user_id.
here is my code –
$list = Plot::active()
->whereNotNull('user_id')
->distinct('user_id')
->with('user')
->paginate(10);
but here "distinct(‘user_id’)" not working. I want only unique user_id.
2
Answers
I solved the problem in this way -
To get unique data based on
user_id
, you can use thegroupBy()
method instead. Here’s how you can modify your code:The
groupBy()
method ensures that the query groups the results byuser_id
, effectively making them distinct.