【问题标题】:How to attach multiple images dynamically in Laravel-Slack Webhook?如何在 Laravel-Slack Webhook 中动态附加多个图像?
【发布时间】:2020-11-21 18:12:02
【问题描述】:

我正在尝试在 Slack 通知中发布多张图片。如果我手动添加“附件”,它允许但我想动态添加附件,即使用循环。

以下代码适用于手动附件:

return (new SlackMessage)->attachment(function (SlackAttachment $attachment) {
                           $attachment->title('Title1')
                                      ->image('Image1.jpg');
                        })
                        ->attachment(function (SlackAttachment $attachment) {
                           $attachment->title('Title2')
                                      ->image('Image2.jpg');
                    });

但我不想手动传递“附件”,我想根据循环次数自动链接“附件”。

我该如何解决这个问题?

【问题讨论】:

  • 使用循环还不够?
  • @Berto99 那么解决方案是什么?

标签: laravel for-loop foreach slack slack-api


【解决方案1】:

类似这样的:

$message = new SlackMessage;
foreach($something as $something_else){
      $message->attachment(function (SlackAttachment $attachment) {
          $attachment->title('Title1')
                     ->image('Image1.jpg');
      })
 }
 return $message

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 2011-06-08
    相关资源
    最近更新 更多