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

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

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

$user = User::where('user_id' , 10);
$user->count();
tgugnani: Web Stuff Enthusiast.