Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Fast2Sms Laravel Package

itxshakil/laravel-fast2sms

View on GitHub
Deep Wiki
Context7

Laravel Notifications

Laravel Fast2SMS provides two notification channels out of the box: fast2sms for SMS and whatsapp for WhatsApp.


SMS Notifications

1. Add the Channel

Return 'fast2sms' from your notification's via() method:

use Illuminate\Notifications\Notification;
use Shakil\Fast2sms\Enums\SmsRoute;
use Shakil\Fast2sms\Notifications\Messages\SmsMessage;

class OrderShipped extends Notification
{
    public function __construct(private readonly Order $order) {}

    public function via(object $notifiable): array
    {
        return ['fast2sms'];
    }

    public function toSms(object $notifiable): SmsMessage
    {
        return SmsMessage::create("Your order #{$this->order->id} has shipped!")
            ->withRoute(SmsRoute::QUICK);
    }
}

2. Add Routing to Your Model

Add routeNotificationForFast2sms() to your notifiable model:

use Illuminate\Notifications\Notifiable;

class User extends Model
{
    use Notifiable;

    public function routeNotificationForFast2sms(): string
    {
        return $this->phone_number;
    }
}

3. Send the Notification

$user->notify(new OrderShipped($order));

// Or via the Notification facade
Notification::send($users, new OrderShipped($order));

SmsMessage Builder

SmsMessage::create('Your message here')
    ->withRoute(SmsRoute::QUICK)       // Set SMS route
    ->withNumbers(['9876543210'])      // Override recipient numbers
    ->from('MYAPP');                   // Override sender ID

Deprecated Methods (v1 → v2)

Old (deprecated) New
content('...') withContent('...')
route(...) withRoute(...)
to('...') withNumbers('...')

WhatsApp Notifications

1. Add the Channel

use Illuminate\Notifications\Notification;
use Shakil\Fast2sms\Notifications\Messages\WhatsAppMessage;

class OrderShipped extends Notification
{
    public function via(object $notifiable): array
    {
        return ['whatsapp'];
    }

    public function toWhatsApp(object $notifiable): WhatsAppMessage
    {
        return WhatsAppMessage::text("Your order #{$this->order->id} has shipped!");
    }
}

2. Add Routing to Your Model

public function routeNotificationForWhatsapp(): string
{
    return $this->phone_number;
}

WhatsAppMessage Builder

// Text
WhatsAppMessage::text('Hello!');

// Image
WhatsAppMessage::image('https://example.com/image.jpg');

// Document
WhatsAppMessage::document('https://example.com/file.pdf');

// Location
WhatsAppMessage::forLocation(lat: 28.6139, lng: 77.2090);

// Interactive
WhatsAppMessage::forInteractive([/* ... */]);

Sending to Multiple Channels

public function via(object $notifiable): array
{
    return ['fast2sms', 'whatsapp', 'mail'];
}

See Also

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium