Slack Integration With Laravel

|
| By Maniraj Singh
  1. Firstly, create a slack channel with the (composer requires laravel/slack-notification-channel ) command.
  2. Create a notification in the laravel project with the command (php artisan make: notification SlackNotification).
  3. Create toSlack method in the SlackNotification.
  4. Add routeNotificationForSlack in the user model to call toSlack method.
  5. 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”
}

Leave a Reply

Your email address will not be published. Required fields are marked *