Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

amenkhlifi's avatar

PHP artisan serve does not work

when I tape the command php artisan serve I have this error and I don't know why I'm having this problem I'm using PHP 5.6 and laravel 5.4

[ErrorException] count(): Parameter must be an array or an object that implements Countable

0 likes
4 replies
kvithalani's avatar

@AMENKHLIFI may be somewhere you have used count() function on single data: for example

$getData = User::find($id);
if(count($getData)>0) {
}

It will give the error. because it is not an array. count function is only used will array. you can use it with get() or all() method.

1 like
amenkhlifi's avatar

This is the function



public static function recaptcha_data(){
    $recaptcha_data = array();
    $_this  =  new self;
    $settings_data = $_this->settingsData;
    if(count($settings_data) > 0){
      $recaptcha_data = $settings_data['general_settings']['recaptcha_options'];
    }
    return $recaptcha_data;
  }
    


kvithalani's avatar

@amenkhlifi what are you getting in $settings_data object. can you show me the log of that. Is it in array?

munazzil's avatar

@amenkhlifi

Try as like below.  

public static function recaptcha_data(){
    $recaptcha_data = array();
    $_this  =  new self;
    $settings_data = $_this->settingsData;
    if(count($settings_data) > 0){
     $recaptcha_data = $settings_data['general_settings']['recaptcha_options'];
    }else{
 return $recaptcha_data;
    }
}

Please or to participate in this conversation.