I have Upgraded my laravel application php version to php 7.2 this week and from then I am facing big problems in my laravel application. before upgrading php to 7.2 every thing worked pefectly.
the main issue is about count() and array_merge() functions which is throwing this error:
for array_merge()
function the code is as below:
$array = array_merge(
$model->toSearchableArray(), $model->scoutMetadata()
);
if (empty($array)) {
return;
}
ErrorException · array_merge(): Argument #1 is not an array.
and I am facing count()
error for example at this code when the model returns no records and returns null:
count(TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get())
count()
: Parameter must be an array or an object that implements Countable.
my laravel version is 5.4
now my question is how can I solve the issues, and does upgrading to laravel 5.5 solve any of the issues?
In PHP 7.2 changed count()
behavior in the following RFC: https://wiki.php.net/rfc/counting_non_countables
But you can get count using ->count()
in laravel, here is an example of it:
$count = TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get()->count();
This way you can get total records count.
Just add @
before count
. I.E.
@count(object or array);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With