Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

How To Send Slack Notification with Laravel

It seems like a topic for basic Laravel developer, but while it’s easy to send emails, but the whole system of various notifications is much deeper, and worth studying. Sub-topics:

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.

composer require laravel/slack-notification-channelCode language: JavaScript (javascript)

Configure Incoming Webhooks

First, you need to install the Slack Application, we have to get the Slack webhook URL. For that login, to your Slack application and after login you will land on the main screen now on the left panel

In Your Slack Application, you can see a + sign in the left corner, Add Apps, Click on the icon, you will land on an app search page where you need to search incoming-webhook in the search bar.

Now install the incoming-webhook application Now go to the setting tab inside the incoming-webhook app which you just install into your slack application. you need to provide the channel name there and you’ll get a Webhook URL.

Webhook URL

Copy the Webhook URL From the slack website and past it into the very bottom or wherever you like in the .env file which is in your laravel application’s root file

.envfile for pusher

That’s what you need from the Slack app, Now you have to configure your laravel application. For that, you need to create a notification section in laravel. For that, you just need to run this command in your commander.

php artisan make:notification TestNotificationCode language: CSS (css)

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.

Now add the Slack in a new method’s returned array and create your first slack notification in the new method named toSlack().

public function toSlack($notifiable)
    {
        $message = "Famous Hello World!";
        
        return (new SlackMessage)
                ->from('Ghost', ':ghost:')
                ->to('#channel-name')
                ->content('Fix service request by '.$message);
    }Code language: PHP (php)

 Now its time to trigger this notification.

Notification::route('slack', env('SLACK_HOOK'))
      ->notify(new TestNotification());Code language: PHP (php)

Complete code for Notification

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

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Related Posts

What is Laravel and use cases of Laravel?

What is Laravel? Laravel is an open-source, free PHP web framework designed for the development of web applications following the model-view-controller (MVC) architectural pattern. It was generated…

Read More

Complete guide of Laravel certification courses, tutorials & training

What is Laravel Laravel is a reliable and simple to use open-source PHP framework. It adheres to the model-view-controller pattern of design. Laravel makes use of pre-existing…

Read More

Top 100 laravel interview questions and answers

1) What is Laravel? Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural pattern….

Read More

[SOLVED] Laravel : Supervisor FATAL/BACKOFF Exited too quickly (process log may have details)

Problem I’m trying to use Laravel queues with a supervisor but the service is not working properly. When I try to check status:$ sudo supervisorctl status$ laravel-worker:laravel-worker_00:…

Read More

How to Login with Token in Laravel PHP Framework?

How to Login with Token in Laravel PHP Framework? Step 1. Create a new Project, so write down the following command on Git Bash: Step 2. Move…

Read More

Directory Structure Of Laravel Application

devopsschool – This is Project Folder app – The app directory contains the core code of your application. bootstrap – The bootstrap directory contains the app.php file…

Read More