Jose Jimenez
Software Architect & Developer
> >

Create pre and post deploy notifications in Laravel Forge using Slack

Published in Laravel, Forge on Dec 31, 2022

Pro-Tip when working with Laravel Forge, is to send a notification when a deployment is kicked off. Doing this for deployments will inform the team when a deployment starts and ends, allowing you to be informed of the status without having to keep rechecking Forge. In this example I will use Slack.

First you will need your webhook, you can read about how to configuring it here.

Configuring post deploy webhook

Out of the box Forge comes configured with a post deploy webhook that we can configure. To enable, let's go to our Forge project -> Notifications -> Click the "Add Channel" button, select Slack and paste your code in. Now when our deployment completes, we will automatically get a notification in our Slack Channel that deployment completed.

Configuring pre deploy webhook

Unfortunately Forge does not come with a pre deploy webhook like the post deploy one, however we can add one by going to our Forge Project -> Deployment Hooks -> Click "Add Hook" button. In the Script section, you will add:

  "text": "Deployed to *{{ name }}*",
  "attachments": [
      "author_name": "{{ author }}",
      "text": "Code is now being deployed",
      "color": "#00a3e0"
curl -s -X POST -H "Content-type: application/json" --data "$payload" $url

If you have multiple servers configured in Forge, it's important to checkbox one of the servers to not be bombarded with multiple messages. You can configure your notification by using a variation of hook variables which you can read about here.

In this article you learned how to send pre and post deploy notifications utilizing Slack, however additional forms of notifications can be configured which will vary by provider.