My Java experience tells me I can create generic collections like this:
Collection<E> collection = new Collection<E>();
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.
For example, I was thinking of this when creating a Laravel model transformer function as below:
Current Laravel function:
public function transformMultiple(Collection $models){
$collection = collect();
foreach($models as $m){
$collection->push($this->transform($m));
}
return $collection;
}
Hypothetical function using generics:
public function transformMultiple(Collection<Foo> $models){
$collection = collect();
foreach($models as $m){
$collection->push($this->transform($m));
}
return $collection;
}