2016-12-04 1 views
0

계정, 게시, 댓글, 작업 및 상호 작용앱 서비스 제공 업체 사용 방법

나는 오류가 있습니다. 이것은 오류입니다 :

Type error: Argument 1 passed to App\Providers\AppServiceProvider::App\Providers{closure}() must be an instance of App\Account, instance of App\Post given

이 내 코드입니다 :

public function boot(){ 
    Post::saved(function(Account $account, Account $from, Post $post){ 
     if ($post->isIntractable()) { 
      $interaction = Interaction::add($post, $from, $account); 
      Task::add($interaction); 
     } 
    }); 

    Comment::saved(function ($account, $from, Comment $comment){ 
     $interaction = Interaction::add($comment, $from, $account); 
     Task::add($interaction); 

     $raw_data = json_decode($comment->raw_data, true); 
     $replies = Comment::makeOrUpdateGraphEdge(array_get($raw_data, 'comments')); 
     foreach ($replies as $reply) { 
      $raw_data = json_decode($reply->raw_data, true); 
      $from = $this->cacheAccount($raw_data['from']); 
      $this->cacheReplies($account, $from, $comment, $reply); 
     } 
    }); 
} 

private function cachePost(Account $account, Account $from, Post $post) { 
    $post->account()->associate($account); 
    $post->from()->associate($from); 
    $post->save(); 
    /* if ($post->isIntractable()) { 
     $interaction = Interaction::add($post, $from, $account); 
     Task::add($interaction); 
    }*/ 
} 

답변

0

모델 이벤트는 해당 이벤트를 트리거 한 모델입니다 하나 개의 매개 변수를 기대합니다. 예를 들어, 귀하의 경우 :

Post::saved(function(Post $post){ 
    if ($post->isIntractable()) { 
     $interaction = Interaction::add($post, $from, $account); // this will throw error as the variables are not recognized by the event. 
     Task::add($interaction); 
    } 
}); 

더 많은 매개 변수를 전달해야하는 경우

, 당신은 save() 조치를 트리거하기 전에 Post 모델에 이러한 매개 변수를 첨부 할 수있는 방법을 찾아야합니다.

관련 문제