2017-02-08 2 views
-2

[InvalidArgumentException] 예약 된 콜백 이벤트가 잘못되었습니다. 문자열 또는 호출 가능해야합니다. 당신은했습니다, 여기에안녕하세요, laravel 및 php에 약간의 새로운 오류가 발생했습니다 [InvalidArgumentException]

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

: 이이를했습니다, 당신은 call 방법으로 매개 변수의 잘못된 유형을 통과했기 때문에 오류가 예를 들어, 발생합니다

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'; 
} 
+0

스택 추적뿐만 아니라 오류와 함께 줄 번호가 제공됩니다. 둘 다 코드를 디버깅하는 데 매우 유용 할 것입니다. – Bytewave

답변

1

코드입니다 사실 $this->consult() 메서드라고하며 결과를 전달했습니다.

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

하지만, 여기에 호출 방법, 실제로 중 하나 Callable 또는 String을 받아들 이는이 동일합니다. String의 경우 문자열은 [email protected] 또는 SomeClass::staticMethodName이 될 수 있습니다. 호출의 경우

, 그것은 될 수 중 하나 Closure/Anonymous Function 또는 [$anObject, 'someMethod'] 같은 인스턴스 메소드와 귀하의 경우는 다음과 같을 수

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

또한,이 경우에는, 당신의 consult 방법해야 (아마도 확실하지 않으므로 먼저 보호 해보십시오) protected 대신 public이됩니다.