Video Version of the Lesson
[Only for premium members]
[Only for premium members]
[Only for premium members]
Let's explore more complex HTTP Client usage by building a Discord webhook notification to alert your community when new tutorials are published.
We will send a message to the Discord server after submitting this long form:
This is the message we'll see on Discord:
Discord doesn't provide an official PHP package, unlike many APIs, so we must use the Laravel HTTP Client.
By the end of this lesson, you will learn how to:
Discord webhooks are HTTP endpoints that allow external applications to send messages directly to Discord channels.
Before diving into code, you need a webhook URL from Discord:
The webhook URL looks like: https://discord.com/api/webhooks/123456789/abcdefghijklmnop
This is the URL we would send our POST request to:
$webhookUrl = 'https://discord.com/api/webhooks/123456789/abcdefghijklmnop';$payload = []; // we will later fill this arrayHttp::withHeaders(...) ->post($webhookUrl, $payload);
Critical note: Treat webhook URLs like...