Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count(): Parameter must be an array or an object that implements Countable

I'm facing strange case. I face an error in production env not while in dev it's working fine.

Development: Laravel 5.4.28 PHP 7.0.13 MYSQL 5.7.17

Production: Laravel 5.4.28 PHP 7.2.1 MYSQL 5.7.20

In implementation code. I used:

namespace App; use Illuminate\Support\Facades\Storage; use Laravel\Scout\Searchable; use Illuminate\Database\Eloquent\Model;  class Artwork extends Model {   use Searchable; 

In development it works fine. But in production it gives me this error: count(): Parameter must be an array or an object that implements Countable in Builder.php (line 936)

as you can see in this pic:

enter image description here

Any idea what is the reason behind this? and how to fix?

like image 614
Khaled Al-Shehri Avatar asked Jan 19 '18 14:01

Khaled Al-Shehri


People also ask

What is the use of count () function in PHP?

The count() function returns the number of elements in an array.

Is count an array function?

Array#count() : count() is a Array class method which returns the number of elements in the array. It can also find the total number of a particular element in the array. Syntax: Array. count() Parameter: obj - specific element to found Return: removes all the nil values from the array.

How do I count the length of a object in PHP?

The count() function is used to count the elements of an array or the properties of an object. Note: For objects, if you have SPL installed, you can hook into count() by implementing interface Countable. The interface has exactly one method, Countable::count(), which returns the return value for the count() function.

Is PHP an array?

Definition and Usage. The is_array() function checks whether a variable is an array or not. This function returns true (1) if the variable is an array, otherwise it returns false/nothing.


1 Answers

Put this code at the beginning of your route file, it will work fine

if(version_compare(PHP_VERSION, '7.2.0', '>=')) {     error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING); } 
like image 179
Akash Kulshrestha Avatar answered Sep 21 '22 17:09

Akash Kulshrestha