count():参数必须是一个数组或者一个实现了Countable的对象 [英] 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.
开发:Laravel 5.4.28PHP 7.0.13MYSQL 5.7.17
Development: Laravel 5.4.28 PHP 7.0.13 MYSQL 5.7.17
生产:Laravel 5.4.28PHP 7.2.1MYSQL 5.7.20
Production: Laravel 5.4.28 PHP 7.2.1 MYSQL 5.7.20
在实现代码中.我用过:
In implementation code. I used:
namespace App;
use IlluminateSupportFacadesStorage;
use LaravelScoutSearchable;
use IlluminateDatabaseEloquentModel;
class Artwork extends Model
{
use Searchable;
在开发中它运行良好.但是在生产中它给了我这个错误:count():参数必须是一个数组或者一个实现了Countable的对象在 Builder.php(第 936 行)
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:
知道这背后的原因是什么吗?以及如何修复?
Any idea what is the reason behind this? and how to fix?
推荐答案
把这段代码放在你的route
文件的开头,它会正常工作
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);
}
这篇关于count():参数必须是一个数组或者一个实现了Countable的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!