title: Laravel Collection get unique values from nested datastructure
body: <p>I want to use <a href="http://laravel.com/docs/5.1/collections#method-unique" rel="noreferrer">Laravel 5.1 Collection's Unique</a> method to filter unique IDs from nested objects.</p>
  
  <p>Given the data structure</p>
  
  <pre><code>{
    "key1": [
      {"id": 1},
      {"id": 1}
    ],
    "key2": [
      {"id": 1},
      {"id": 2}
    ]
  }
  </code></pre>
  
  <p>I want to return the same datastructure with duplicate <code>id 1</code> removed from "key 1". </p>
  
  <p>I wanted to use <code>$unique = $collection-&gt;unique('id');</code>, but this doesn't seem to apply to a nested datastructure as I have.</p>
  
  <p>So I thought to use $collection</p>
  
  <pre><code>    $input = $request-&gt;all();
  
      $collection = collect($input);
  
      $collection-&gt;each(function($obj, $key) {
          //$key is "key1", "key2"
          //obj is the associated array of objects containing IDs
      })-&gt;unique('id');
  </code></pre>
  
  <p>I don't quite know how to structure this.</p>
  
  <p>The result structure should be:</p>
  
  <pre><code>{
    "key1": [
      {"id": 1}
    ],
    "key2": [
      {"id": 1},
      {"id": 2}
    ]
  }
  </code></pre>