Laravel: Rate-Limit API Routes with Throttle
Protect your Laravel API from abuse with the built-in throttle middleware — limit requests per minute per user or IP.
Send WhatsApp messages from Laravel through a provider API — order updates, OTPs and alerts in a few lines.
29 lines · Updated Nov 26, 2026
<?php
namespace App\Services;
use Illuminate\Support\Facades\Http;
class WhatsAppService
{
public function send(string $to, string $message): bool
{
$response = Http::withHeaders([
'Authorization' => 'Bearer ' . config('services.whatsapp.token'),
])->post(config('services.whatsapp.endpoint'), [
'to' => $to,
'message' => $message,
]);
return $response->successful();
}
}
// config/services.php
// 'whatsapp' => [
// 'endpoint' => env('WHATSAPP_API_URL'),
// 'token' => env('WHATSAPP_API_TOKEN'),
// ],
// Usage:
// app(WhatsAppService::class)->send('923001234567', 'Your order is on the way!');
WhatsApp is where customers actually read messages — order confirmations, OTPs, delivery updates and appointment reminders get far more attention there than in email. This snippet sends a WhatsApp message from a Laravel application through a messaging API using Laravel's HTTP client, so you can notify customers straight from your code.
config/.env, never hard-coded.923001234567.Is it free? Providers charge per conversation or message, with prices varying by country and message category. Check your provider's current pricing.
Related: Delayed queued job with retries · What is Laravel Livewire?
Save the class as app/Services/WhatsAppService.php, add the config block to config/services.php, and set WHATSAPP_API_URL and WHATSAPP_API_TOKEN in .env. Replace the endpoint payload with your provider's format.
Share this snippet
Protect your Laravel API from abuse with the built-in throttle middleware — limit requests per minute per user or IP.
Generate a sitemap.xml from your database in Laravel — always up to date, no file to maintain by hand.
Add one search scope to any Eloquent model and search across several columns with a single method call.