bob
bob

Reputation: 197

Laravel selecting all rows just once if same some_id

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

Answers (1)

Polaris
Polaris

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

Related Questions