Reputation: 197
Suppose I have a product table in which there are those columns: id, user_id How can I retrieve all the rows of this table just once if two rows have the same user_id in Laravel?
Upvotes: 0
Views: 1373
Reputation: 1249
This will return all columns in the product model without any duplicates of user_id. So, it will return, just one row per user_id.
$productModel->groupBy('user_id')->get();
Upvotes: 2