本周,我已经将我的laravel应用程序php版本升级为php7.2,从那时起,我的laravel应用程序就面临着很大的问题。在将php升级到7.2之前,每件事情都做得很好。
主要问题是关于抛出此错误的array_merge()计数()、和函数:
对于array_merge()
函数,代码如下:
$array = array_merge(
$model->toSearchableArray(), $model->scoutMetadata()
);
if (empty($array)) {
return;
}
ErrorException·array_merge():参数#1不是数组。
例如,当模型不返回记录并返回null时,我将面临count()
错误:
count(TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get())
count()
:参数必须是实现可数的数组或对象。
我的laravel版本是5.4
现在我的问题是如何解决这些问题,升级到Laravel5.5是否解决了任何问题?
发布于 2017-12-15 01:08:34
在中,PHP7.2中,在以下RFC中更改了count()
行为:可数
但是您可以使用->count()
在laravel中进行计数,下面是一个例子:
$count = TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get()->count();
这样你就能得到记录的总数。
发布于 2018-03-09 02:31:04
只需在@
之前添加count
即可。也就是。
@count(object or array);
发布于 2017-12-14 23:51:40
要解决() array_merge()问题,请尝试以下步骤:
return ['source' => null, 'maxLength' => null, 'method' => null, 'separator' => '-', 'unique' => true, 'uniqueSuffix' => null, 'includeTrashed' => false, 'reserved' => null, 'onUpdate' => false, ];
php artisan config:cache
解决count()问题的:尝尝这个
count(): Parameter must be an array or an object that implements Countable.
实际上,这不是一个错误,而是一种预期的行为。Laravel5.4或5.5与PHP7.2不完全兼容。在PHP7.2 看看这个上,Count()行为只是改变
另一种方法就是使用PHP7.1或更低的版本,直到兼容性问题得到解决。
https://stackoverflow.com/questions/47827268
复制相似问题