Laravel

Send SMS in Laravel with Http::

Laravel apps call the Taysend REST API with the built-in HTTP client — no official Laravel package. Wrap sends in a service class, store keys in .env, and verify webhook signatures in a dedicated controller.

Config

Configuration

.env
# .env
TAYSEND_KEY=sms_test_your_key
TAYSEND_API_URL=https://api.taysend.com

Optionally add services.taysend in config/services.php mapping url and key from env.

Service

Service class

app/Services/TaysendSms.php
<?php

namespace App\Services;

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

class TaysendSms
{
    public function send(string $to, string $message, string $senderId = 'TAYSEND'): array
    {
        $base = config('services.taysend.url', env('TAYSEND_API_URL', 'https://api.taysend.com'));
        $key = config('services.taysend.key', env('TAYSEND_KEY'));

        $response = Http::withHeaders([
            'Authorization' => 'Bearer ' . $key,
            'Idempotency-Key' => (string) Str::uuid(),
        ])->post("{$base}/v1/messages", [
            'to' => $to,
            'sender_id' => $senderId,
            'message' => $message,
            'type' => 'transactional',
        ]);

        $response->throw();
        return $response->json();
    }
}

OTP

OTP in a controller

verify/send
$response = Http::withToken(config('services.taysend.key'))
    ->post(config('services.taysend.url') . '/v1/verify/send', [
        'to' => '+233200000001',
        'locale' => 'en',
    ]);

Webhooks

Webhooks route

Register a POST route, read raw body, verify t= and v1= headers, then update your models. Exclude the route from CSRF middleware.

Explore

Related

Each page answers a different question. They are not copies of this one.

Next

Wire Taysend into your Laravel app.