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

This is my solution:

count(array($variable));

hope it works!


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:[]))

Note that here, When you use the count() method, there should be countable element, like an array or object that implement ArrayAccess.

Admin::where('email',$request->email)->first();

But the first() method give you single element, not a collection or array. The get() method returns you countable a collection with found elements

Instead of using count you can directly check variable itself is it defined or null

if($admin){
  // do something here
}

or you can use is_null() method

if(!is_null($admin)){
  // do something here
}

Tags:

Php

Laravel