How to remove the same item from Collection laravel?

I have this collection:

Collection {#604 ▼
  #items: array:4 [▼
    0 => CarsMark {#596 ▶}
    1 => CarsMark {#594 ▶}
    2 => CarsMark {#594 ▶}
    3 => CarsMark {#595 ▶}
  ]
}

As you can see there is two the same items (594). How can i retrieve all items from with collection without the same items?

Upvotes: 1

Views: 150

Answers (1)

Joseph Silber
Joseph Silber

Reputation: 219920

Use the collection's unique method:

$unique = $collection->unique();

Upvotes: 2

Related Questions