Fix – count(): Parameter … implements Countable Error Laravel Eloquent

If you are working with Laravel Eloquent and got following exception -> count(): Parameter must be an array or an object that implements Countable

This is probably because of the new version of PHP > 7 , count() function only works only on array (or an object that implements Countable)

When you are using Eloquent, the result are in object of the model, rather then in the array.

If you have a query something like below

Livewire Component Library
$user = User::where('user_id', 10);
count($user) // Will throw exception

Instead, you can make use of count() method on the model

Host Laravel Application on DigitalOcean

Use coupon 5balloons on this Cloudways Affiliate URL to get special discount.
$user = User::where('user_id' , 10);

Site Footer