Level 88
You can use the unique method for that. Also you can pass in a callback to the method to do some more advanced stuff
Documentation: https://laravel.com/docs/master/collections#method-unique
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have an collection like this:
Collection {#560 ▼
#items: array:3 [▼
429 => array:3 [▼
0 => array:5 [▼
"id" => 1242
"post_id" => 2040
"post" => array:21 [▶]
]
1 => array:5 [▼
"id" => 1245
"post_id" => 2047
"post" => array:21 [▶]
]
]
430 => array:3 [▼
0 => array:5 [▼
"id" => 1243
"post_id" => 2040
"post" => array:21 [▶]
]
431 => array:3 [▼
0 => array:5 [▼
"id" => 1245
"post_id" => 2041
"post" => array:21 [▶]
]
1 => array:5 [▼
"id" => 1244
"post_id" => 2047
"post" => array:21 [▶]
]
]
]
}
if the post_idlike 2040 and 2047 from array 429 is found in the other array 431 then return only the only array 431 so i would have the duplicated removed
Please or to participate in this conversation.