Show The Data Without Duplicates

Laravel has a good number of ready-to-use functions, that are very useful. Such functions are not very often used by developers, yet important in many cases.

List The Duplicate Data Once

The Duplicates method is mostly good for editorial purposes. An admin can manage the posts by looking for duplicate posts, that are posted by the members.

$collection = collect(["12", "12", "24", "24", "54"]);
$collection->duplicates();

Here 12 and 24 are repeated and we would not like the page to fill with the mess repeating the same characters. So by using $collection->duplicates() we can list all the duplicate characters once without calling others.

See, you will not get 54 but the output will be 12 and 24.

Related Posts