macellan/twilio

Twilio SMS notification channel for Laravel
3,779 2
Install
composer require macellan/twilio
Latest Version:v2.0.0
PHP:^8.2
License:MIT
Last Updated:Mar 25, 2025
Links: GitHub  ·  Packagist
Maintainer: epicentre

Twilio SMS Notifications Channel for Laravel

Tests Latest Stable Version Total Downloads

This package makes it easy to send sms notifications using Twilio with Laravel 12.x

Contents

Installation

You can install this package via composer:

composer require macellan/twilio

Setting up the Twilio service

Add your Twilio configs to your config/services.php:

// config/services.php
...
    'sms' => [
        'twilio' => [
            'account_sid' => env('TWILIO_ACCOUNT_SID', ''),
            'auth_token' => env('TWILIO_AUTH_TOKEN', ''),
            'from' => env('TWILIO_FROM', ''),
            'enable' => env('TWILIO_ENABLE', false),
            'debug' => env('TWILIO_DEBUG', false), // Will log sending attempts and results
            'sandbox_mode' => env('TWILIO_SANDBOX_MODE', false), // Will not invoke API call
        ],
    ],
...

Usage

You can use the channel in your via() method inside the notification:

use Illuminate\Notifications\Notification;
use Macellan\Twilio\TwilioSmsMessage;

class TestNotification extends Notification
{
    public function via($notifiable): array
    {
        return ['twilio'];
    }

    public function toTwilio(object $notifiable): TwilioSmsMessage
    {
        return new TwilioSmsMessage('Twilio test message');
    }
}

In your notifiable model, make sure to include a routeNotificationForSms() method, which returns a phone number.

public function routeNotificationForSms(): string
{
    return $this->phone;
}

On-Demand Notifications

Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification:

Notification::route('sms', '+905554443322')  
            ->notify(new TestNotification());

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Credits

Related Packages

vikilaboy/laravel-twilio-notifications

Provides Twilio notification channel for Laravel

15,396 0
macellan/netgsm

Netgsm SMS notification channel for Laravel

5,739 3
laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

9,089,784 258
gr8shivam/laravel-sms-api

Laravel package to provide SMS API integration. Any SMS vendor that provides RES...

42,428 101
rayzenai/laravel-sms

A Laravel package for sending SMS messages with support for both string and bigi...

4,000 1