Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

prakashbhatnager@gmail.com's avatar

Is it better to implement countable interface on model class

Is it better to implement countable interface on model class for using count() on that models? or should i use count(array($modelObj))

I am just updgrading my laravel version, so i encountered the warning count(): Parameter must be an array or an object that implements Countable

0 likes
2 replies
MichalOravec's avatar

What is your goal?

Result for single model of this count(array($modelObj)) is everytime just 1.

With this you get a count of properties in your model.

count($modelObj->toArray());
1 like

Please or to participate in this conversation.