- Firstly, create a slack channel with the (composer requires laravel/slack-notification-channel ) command.
- Create a notification in the laravel project with the command (php artisan make: notification SlackNotification).
- Create toSlack method in the SlackNotification.
- Add routeNotificationForSlack in the user model to call toSlack method.
- Call SlackNotification from where you want to send a message.
Code:
data = $data;
}
public function via($notifiable)
{
return ['slack'];
}
public function toSlack($notifiable)
{
Log::info('in SlackMessage noti');
return (new SlackMessage)
->content(Test slack notification');
}
}
User model
public function routeNotificationForSlack($notification)
{
return “https://hooks.slack.com/services/dhfshdk”
}