title: Laravel: Best way to compare two collections: whereIn?
body: <p>I have a table with categories, one table with products and another table products_user which tracks the products a user owns.</p>
  
  <p>When displaying products on a page it should change a button from Buy to Bought if a user owns the product.</p>
  
  <p>I get the products to display through $categories->products. What is the most efficient way to find out which of these products a user already owns?</p>
  
  <p>I don't want to load the entire collection of the user owned products into the memory since these could be several thousands. I also don't want to create a Mysql query for each check.</p>
  
  <p>There is an option for a wherein clause. But even then I am that there is a smarter way to create this clause without looping through every product to build an array.</p>
  
  <p>Can someone help me to come up with a good logic? thank you</p>