count(): Parameter must be an array or an object that implements Countable
最近將php版本從7.1升級到7.2 然後
count(): Parameter must be an array or an object that implements Countable
count函式在PHP7.2版本中已經是嚴格要求傳入的引數型別了,只能是陣列或者 Countable 物件。而在laraval 5.3
protected function callScope(callable $scope, $parameters = []) { array_unshift($parameters, $this); $query = $this->getQuery(); //問題出現在這裡 $query->wheres 結果為 null 導致count報錯 $originalWhereCount = count($query->wheres); $result = $scope(...array_values($parameters)) ?: $this; if ($this->shouldNestWheresForScope($query, $originalWhereCount)) { $this->nestWheresForScope($query, $originalWhereCount); } return $result; }
解決方案:
1.降低php版本至於7.2以下
2.保證至少有一個條件 比如 $query->where('deleted_at','==','null')