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"
This is my solution:
hope it works!
$admin
variable is neither array nor object that implements countable. When you usefirst()
the result will be a model object if record is found else it will be null. For this condition you can use:Just replace
if (count($admin))
withif (!empty($admin))
.And when you use
get()
method to get multiple records you can check by:It happens because of in PHP 7.2 NULL in count() return Warning. You can try to change
to
Note that here, When you use the
count()
method, there should be countable element, like an array or object.But the
first()
method give you single element, not a collection or array. Theget()
method returns you countable a collection with found elementsInstead of using count you can directly check variable itself is it defined or null
or you can use
is_null()
methodUse
isset($admin->id)
instead ofcount($admin)
Try this :
output: Warning: count(): Parameter must be an array or an object that implements Countable in … on line 12 // as of PHP 7.2
if condition should be like: