W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
你還可以添加 “附件” 到 Slack 消息。相對簡單文本消息,附件可以提供更加豐富的格式選項(xiàng)。在這個(gè)例子中,我們會(huì)發(fā)送一個(gè)在應(yīng)用程序中出現(xiàn)的異常錯(cuò)誤通知,包含查看更多異常細(xì)節(jié)的鏈接:
/**
* Get the Slack representation of the notification.
*
* @param mixed $notifiable
* @return SlackMessage
*/
public function toSlack($notifiable)
{
$url = url('/exceptions/'.$this->exception->id);
return (new SlackMessage)
->error()
->content('Whoops! Something went wrong.')
->attachment(function ($attachment) use ($url) {
$attachment->title('Exception: File Not Found', $url)
->content('File [background.jpg] was not found.');
});
}
上面的示例會(huì)生成一個(gè)如下所示的 Slack 消息:
附件還允許你指定要呈獻(xiàn)給用戶的數(shù)組數(shù)據(jù)。為了提高可讀性,給定的數(shù)組會(huì)以表格形式展示:
/**
* 獲取 Slack 形式的通知。
*
* @param mixed $notifiable
* @return SlackMessage
*/
public function toSlack($notifiable)
{
$url = url('/invoices/'.$this->invoice->id);
return (new SlackMessage)
->success()
->content('One of your invoices has been paid!')
->attachment(function ($attachment) use ($url) {
$attachment->title('Invoice 1322', $url)
->fields([
'Title' => 'Server Expenses',
'Amount' => '$1,234',
'Via' => 'American Express',
'Was Overdue' => ':-1:',
]);
});
}
上面的示例會(huì)生成一個(gè)如下所示的 Slack 消息:
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: