[英]count(): Parameter must be an array or an object that implements Countable on laravel
I just set the code as below and it's show the error. 我只是将代码设置如下,并显示了错误。 May I know how to fix it? 我可以知道如何解决它吗?
public function productsCat(Request $request){
$cat_id = $request->cat_id;
$priceCount = count($request->price);
}
如果您使用的是PHP 7.2,请使用@count抑制此错误
You can use the laravel helper (collect): 您可以使用laravel帮助程序(收集):
public function productsCat(Request $request){
$cat_id = $request->cat_id;
$priceCount = collect($request->price)->count();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.