title: Laravel Generic Collections
body: <p>My Java experience tells me I can create generic collections like this:</p>
  
  <pre><code>Collection&lt;E&gt; collection = new Collection&lt;E&gt;();
  </code></pre>
  
  <p>I am wondering if this is possible in Laravel (at least 5.2+)? I have been using Laravel for nearly 3 years, and have just wondered about this now.</p>
  
  <p>For example, I was thinking of this when creating a Laravel model transformer function as below:</p>
  
  <p><strong>Current Laravel function:</strong></p>
  
  <pre><code>public function transformMultiple(Collection $models){
  
          $collection = collect();
  
          foreach($models as $m){
              $collection-&gt;push($this-&gt;transform($m));
          }
  
          return $collection;
      }
  </code></pre>
  
  <p><strong>Hypothetical function using generics:</strong></p>
  
  <pre><code>public function transformMultiple(Collection&lt;Foo&gt; $models){
  
          $collection = collect();
  
          foreach($models as $m){
              $collection-&gt;push($this-&gt;transform($m));
          }
  
          return $collection;
      }
  </code></pre>