It seems like $collection is not always an object, but can also be of type array<integer,object<Ill...tabase\Eloquent\Model>>. Maybe add an additional type check?
If a variable is not always an object, we recommend to add an additional type check
to ensure your method call is safe:
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: