阅读(4728) (6)

Laravel 8 自定义发送者和接收者

2021-07-06 09:24:50 更新

你可以使用 fromto 方法自定义发送者和接收者, from 方法接收一个用户名和 emoji 标识,而 to 方法接收通道或用户名:

/**
 * Get the Slack representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return SlackMessage
 */
public function toSlack($notifiable)
{
    return (new SlackMessage)
                ->from('Ghost', ':ghost:')
                ->to('#other')
                ->content('This will be sent to #other');
} 

还可以使用图片作为 logo 用以取代 emoji:

/**
 * Get the Slack representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return SlackMessage
 */
public function toSlack($notifiable)
{
    return (new SlackMessage)
                ->from('Laravel')
                ->image('https://laravel.com/img/favicon/favicon.ico')
                ->content('This will display the Laravel logo next to the message');
}