1

I have two collections and want to find the same or duplicated items inside two collections. My solution is first merging two collections and create one collection and then using duplicates method find the same items, but I have an error.

$t1 = collect([12, 13, 11]);
$t2 = collect([14, 15, 12, 11]);
$t3 = $t1->merge($t2);
$final = $t3->duplicates(); 

Error

BadMethodCallException Method Illuminate\Support\Collection::duplicates does not exist.

2
  • What is the exact version of Laravel you're using? Commented May 14, 2019 at 17:33
  • version 5.8.Thanks Commented May 14, 2019 at 17:43

2 Answers 2

3

my laravel version was 5.8 and i updated project using composer update and now my laravel version is 5.8.17 and my problem soloved.

Sign up to request clarification or add additional context in comments.

Comments

1

if you want to get the items which are present in the two collections, you can use Laravel collection intersect method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.