Define type of parameter in method in Laravel as a Collection of Model

Viewed 2549

In a Laravel 5 class, I want to properly type-hint a method which receives as parameter a collection of classA items.

public function myMethod( Collection<ClassA> $items ){
    foreach( $items as $item ){
    }
    ...
}

How do I declare my variable $items?

Is it possible in PHP? (By the way, I am using PHP 7.1)

I found a close answer in PHP - Type hint for Laravel Collection or Array.

However, it is not exactly what I need, because I require the method to accept a Collection of ClassA items

0 Answers
Related