Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

count() parameter must be an array or an object that implements countable in laravel

Tags:

This is code here:

protected function credentials(Request $request) {     $admin=admin::where('email',$request->email)->first();     if(count($admin))     {        if($admin->status==0){            return ['email'=>'inactive','password'=>'You are not an active person, Please contact to admin'];            }            else{                return ['email'=>$request->email,'password'=>$request->password,'status'=>1];            }        }        return $request->only($this->username(), 'password');     } 

When i run the code this error become:

"count(): Parameter must be an array or an object that implements Countable"

like image 344
faraz Avatar asked Oct 27 '18 10:10

faraz


2 Answers

This is my solution:

count(array($variable)); 

hope it works!

like image 168
Jericho Manalo Avatar answered Sep 21 '22 17:09

Jericho Manalo


It happens because of in PHP 7.2 NULL in count() return Warning. You can try to change

count($admin) 

to

count((is_countable($admin)?$admin:[])) 
like image 35
Dmytro Huz Avatar answered Sep 20 '22 17:09

Dmytro Huz