Laravel Slack



The gpressutto5/laravel-slack composer package is a Slack notification library for Laravel 5.5 by Guilherme Pressutto: Slack notification for Laravel as it should be. Easy, fast, simple and highly testable. Since it uses On-Demand Notifications, it requires Laravel 5.5 or higher. When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. Created: 2017-09-08 20:59 Updated: 2019-01-18 18:33 laravel5 slack php. Readme.md Laravel 5 and Lumen - Slack API.

Laravel has lots of built-in and advanced features to make any developer impress with. Sending Notifications are one of them. You can send email, SMS or Slack notification with its built-in functionality. In this article, we going to send the slack notification with Laravel.

Laravel Slack

I am going to use Laravel 5.8.x. The setup is pretty easy. If you haven’t setup Laravel yet then please following the Laravel Installation guide from the documentation.

Laravel SlackLaravel slack channel

In this episode we'll show you how to send slack messages from your laravel application. It's super easy to setup. In this video we'll walk you through creating a new Laravel app, including the GuzzleHttp Library, creating a new notification, and sending a test notification. In this video we'll also show you how to setup a slack web hook. A POST to /api/webhook shows that our Slack app is triggering our Laravel application as expected. We’ll now add the functionality to send an SMS when the /ping command is triggered from Slack. Create the Webhook in our Laravel Application. In Laravel, routes are defined in our route files, which are located in the routes directory.

Requirements

  • Slack Notification Channel Package
  • Configure Incoming Webhooks
Laravel

Slack Notification Channel

In the older version of Laravel, Slack notification was built-in configured with the framework. But on this 5.8.x version, they have created a separate package for Slack Notification. First of all, we have to install that package in our application.

Configure Incoming Webhooks

After installation of Slack Notification Channel package, we have to collect the Slack Webhook URL. So first of all, login to your slack application. Now on the main screen, navigate the App menu on the left sidebar at the very bottom.

Now click on the + icon to add the incoming-hook app to your slack application. Once you clicked on the + icon, then browse apps screen will pop up on your screen. Just search the incoming-webhook in the search area.

If you haven’t installed the incoming-webhook app on the slack app then please install it. After installation, the incoming-webhook app, navigate the settings tab on the incoming-webhook section and collect the Webhook URL.

Now copy the Webhook URL and paste it to the .env file at the very bottom or whatever you like.

This is what you need from the Slack app. Now it’s time to create a notification on Laravel. So let’s create our first notification.

The above command will create a Notifications folder on the app folder from where you can find the TestNotification file. So let’s open and start adding it.

Notice the SlackMessage package that we have included on our application.

use IlluminateNotificationsMessagesSlackMessage;

Add the slack value in the via method’s returned array and create your first slack notification in the new method named toSlack().

Laravel Slack

Laravel Slack

Laravel Slack Logging

If you like to more customized notification then please follow the documentation link. Now its time to trigger this notification.

Complete code for Notification

Paste the above code to send the notification to your slack channel and that’s all.

Laravel Slack Notifications Example

Related posts:

  1. Laravel On-Demand Notifications
  2. Custom Validation With Laravel
  3. REST API and Passport Authentication with Laravel
  4. Understanding Laravel Middleware
  5. Laravel Notification – Customize markdown email header and footer
  6. Laravel Mail – Sending Mailable, Markdown Mailable, and Raw HTML