2016-09-21 81 views
0

基本上, this是我想用Hubot在農閒達到的目標。我試過使用Hubot鬆弛附件字段

 attachment = 
     fields: [ 
       { 
       title: "User info" 
       value: json.user 
       short: false 
       } 
     ] 

但這不起作用。 人如果有我怎樣才能使這項工作的例子嗎?

預先感謝^^

回答

0

通過使用

$attachments = [ 
      'text' => "Active codebases: (total = $total)", 
      'attachments' => [ 
       [ 
        'color' => '#3333ff', 
        'fields' => [ 

        ] 
       ] 
      ] 
     ]; 

解決它,然後使用

 $items = $codebases; 

     foreach ($items as $item) 
     { 
      if(LinkedUser::where('codebase_id', $item->id)->get() !== null) { 
       $linkedusers = LinkedUser::where('codebase_id', $item->id)->get(); 

       $userlist = ""; 

       $i = 0; 
       $len = count($linkedusers); 
       foreach ($linkedusers as $linkeduser) 
       { 
        if ($i == $len - 1) { 
         $userlist .= $linkeduser->user_name; 
        } else { 
         $userlist .= $linkeduser->user_name . ",\n"; 
        } 
        $i++; 
       } 

       $a = [ 
        'title' => $item->name, 
        'value' => $userlist, 
        'short' => true 
       ]; 
       $attachments['attachments'][0]['fields'][] = $a; 
      } 
     } 
插入的數據