-2

[InvalidArgumentException] 计划的回调事件无效。必须是字符串或可调用的。这是代码

protected function schedule(Schedule $schedule)
{
    // $schedule->command('inspire')
    //          ->hourly();
   $schedule->call($this->consult());
}

/**
 * Register the Closure based commands for the application.
 *
 * @return void
 */
protected function consult()
{//try {
    $url=DB::table('remote_services')->pluck('url');
   foreach ($url as $url){
       echo $url;
       echo  '   ';}
//}catch (InvalidArgumentException $e ){
  //  echo 'captured exception';
}
4

1 回答 1

1

抛出错误是因为您将错误类型的参数传递给call方法,例如,您有:

$schedule->call($this->consult());

在这里,您实际上已经调用了$this->consult()方法并传递了结果;这相当于:

$methodCallResult = $this->consult();
$schedule->call($methodCallResult);

但是,这里的 call 方法实际上接受 aCallable或 a String。如果是String字符串,可以是SomeClass@methodNameor SomeClass::staticMethodName

在可调用的情况下,它可以是一个Closure/Anonymous Function或一个实例方法[$anObject, 'someMethod'],在您的情况下,它可能是以下内容:

// Call the consult method of same/this class
$schedule->call([$this, 'consult']);

此外,在这种情况下,您的consult方法应该(可能不确定,所以先尝试 protectedpublic代替protected.

于 2017-02-08T20:18:26.143 回答