Download the PHP package itxshakil/laravel-fast2sms without Composer
On this page you can find all versions of the php package itxshakil/laravel-fast2sms. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download itxshakil/laravel-fast2sms
More information about itxshakil/laravel-fast2sms
Files in itxshakil/laravel-fast2sms
Package laravel-fast2sms
Short Description A Laravel package for sending SMS and WhatsApp messages via the Fast2SMS API with a fluent interface.
License MIT
Informations about the package laravel-fast2sms
Laravel Fast2SMS is a first-class Laravel package for sending SMS and WhatsApp messages via the Fast2SMS API. It provides a fluent, type-safe API, Laravel Notifications support, queue integration, a powerful fake for testing, and a rich exception hierarchy โ so you can build reliable messaging features with confidence.
The most complete Fast2SMS integration for Laravel:
- SMS + OTP + DLT + WhatsApp
- Queue + Notifications
- Prevents wasting SMS money in production
Table of Contents
- Features
- Requirements
- Installation
- Quick Start
- Configuration
- Cost-Saving Features
- Sending SMS
- Sending WhatsApp Messages
- Laravel Notifications
- Queuing
- Events & Listeners
- Testing
- Artisan Commands
- Phone Validation
- Error Handling
- Upgrade Guide
- Contributing
- License
Features
- ๐ฑ SMS โ Quick, OTP, and DLT routes with flash and bulk support
- ๐ฌ WhatsApp โ Text, image, document, location, and interactive messages
- ๐ Laravel Notifications โ
SmsChannelandWhatsAppChannelout of the box - โก Queue support โ Dispatch sends as background jobs with per-send overrides
- ๐งช Fake & assert โ
Fast2sms::fake()with 16 rich assertion helpers - ๐จ Typed exceptions โ
AuthenticationException,RateLimitException,ApiException, and more - ๐ฐ Cost-saving features โ Recipient deduplication (on by default), dedup guard, throttle, balance gate, batch splitting, invalid-recipient stripping
- ๐ PHPStan level 6 โ Fully typed, zero suppressions
- ๐ Artisan commands โ Balance monitor, WABA details, event discovery, IDE helper
- ๐ฎ๐ณ Indian phone validation โ
Fast2smsPhonerule class
Requirements
| Requirement | Version |
|---|---|
| PHP | ^8.3 |
| Laravel | ^11.0 | ^12.0 | ^13.0 |
| Fast2SMS account | Sign up free |
Installation
Install via Composer:
The package auto-discovers its service provider. Publish the config file:
Add your API key to .env:
Full installation guide: docs/installation.md
Quick Start
Configuration
After publishing, edit config/fast2sms.php. All keys can be set via environment variables:
| Key | Env Variable | Default | Description |
|---|---|---|---|
api_key |
FAST2SMS_API_KEY |
โ | Your Fast2SMS API key (required) |
default_sender_id |
FAST2SMS_DEFAULT_SENDER_ID |
FSTSMS |
Default DLT sender ID |
default_route |
FAST2SMS_DEFAULT_ROUTE |
dlt |
Default SMS route |
base_url |
โ | https://www.fast2sms.com/dev |
Fast2SMS API base URL (do not change unless instructed) |
timeout |
โ | 30 |
HTTP request timeout in seconds |
driver |
FAST2SMS_DRIVER |
api |
api for real sends, log for local dev |
database_logging |
FAST2SMS_DATABASE_LOGGING |
false |
Log sends to database โ see docs/db-logging.md |
recipients.deduplicate |
FAST2SMS_DEDUP_RECIPIENTS |
true |
Remove duplicate numbers before every send |
recipients.batch_size |
FAST2SMS_BATCH_SIZE |
0 |
Split large lists into chunks (0 = disabled) |
validation.strip_invalid_recipients |
FAST2SMS_STRIP_INVALID |
false |
Strip invalid numbers before sending |
balance_gate.enabled |
FAST2SMS_BALANCE_GATE |
false |
Enable balance check before every send |
balance_gate.threshold |
FAST2SMS_BALANCE_THRESHOLD |
10.0 |
Balance alert threshold (โน) |
balance_gate.abort |
FAST2SMS_BALANCE_ABORT |
true |
Throw InsufficientBalanceException when balance is low |
deduplication.enabled |
FAST2SMS_DEDUP_ENABLED |
false |
Enable idempotency / dedup guard |
deduplication.ttl |
FAST2SMS_DEDUP_TTL |
60 |
Dedup window in seconds |
deduplication.store |
FAST2SMS_DEDUP_STORE |
null |
Cache store for dedup guard (null = default store) |
throttle.enabled |
FAST2SMS_THROTTLE_ENABLED |
false |
Enable send-rate throttle |
throttle.max_per_minute |
FAST2SMS_THROTTLE_MAX |
60 |
Max sends per minute |
throttle.store |
FAST2SMS_THROTTLE_STORE |
null |
Cache store for send-rate throttle (null = default store) |
whatsapp.default_phone_number_id |
FAST2SMS_WHATSAPP_PHONE_NUMBER_ID |
โ | Default WhatsApp phone number ID |
whatsapp.default_waba_id |
FAST2SMS_WHATSAPP_WABA_ID |
โ | Default WhatsApp Business Account ID |
whatsapp.version |
FAST2SMS_WHATSAPP_VERSION |
v24.0 |
WhatsApp API version |
events.enabled |
FAST2SMS_EVENTS_ENABLED |
true |
Enable/disable event dispatching |
queue.enabled |
FAST2SMS_QUEUE_ENABLED |
false |
Send via queue |
queue.connection |
FAST2SMS_QUEUE_CONNECTION |
null |
Queue connection name |
queue.name |
FAST2SMS_QUEUE_NAME |
default |
Queue name |
queue.tries |
FAST2SMS_QUEUE_TRIES |
3 |
Max job attempts |
Use FAST2SMS_DRIVER=log in local/testing environments to log messages instead of making real API calls.
Full configuration reference: docs/configuration.md
Cost-Saving Features
Most cost-saving features are opt-in and disabled by default โ enable only what you need. Recipient deduplication is the exception: it is enabled by default.
Recipient Deduplication
Automatically removes duplicate numbers from the recipient list before every send. This is enabled by default โ set to false to disable:
Invalid Recipient Stripping
Validates each number against the Fast2smsPhone rule, logs a warning for each removed number, and throws ValidationException if all numbers are invalid:
Idempotency / Dedup Guard
Prevents the same message being sent twice within a configurable window (applies to both SMS and WhatsApp):
Throws DuplicateSendException on a repeated identical call within the TTL.
Send-Rate Throttle
Limits the number of sends per minute using a sliding-window cache counter (applies to both SMS and WhatsApp):
Throws ThrottleExceededException when the limit is reached.
Balance Gate
Checks your wallet balance before every send and fires LowBalanceDetected. When abort is true, throws InsufficientBalanceException to prevent the API call (applies to both SMS and WhatsApp):
Batch Splitting
Splits large recipient lists into chunks and issues one API call per chunk:
SMS Credit Estimation
Use SmsMessage helpers to estimate cost before sending:
Full cost-saving features guide: docs/cost-saving-features.md
Full upgrade guide: UPGRADING.md
Sending SMS
Quick SMS
OTP SMS
DLT SMS
Flash SMS
Multiple Recipients
Full SMS guide: docs/sms-guide.md
Sending WhatsApp Messages
Phone number format for WhatsApp: Always include the country code prefix (e.g.
919876543210for India โ91+ 10-digit number). This differs from SMS, which accepts 10-digit numbers directly.
Text
Image
Document
Location
Interactive
Convenience alias:
Fast2sms::viaWhatsApp($to)is shorthand forFast2sms::whatsapp()->to($to). Both are public API;whatsapp()->to(...)is the canonical form.Full WhatsApp guide: docs/whatsapp.md
Laravel Notifications
SMS Notification
Add routeNotificationForFast2sms() to your notifiable model (e.g. User) to tell the channel which number to use:
WhatsApp Notification
Add routeNotificationForWhatsapp() to your notifiable model (e.g. User) to tell the channel which number to use:
Full notifications guide: docs/notifications.md
Queuing
Enable queuing in .env:
Then send as usual โ the package dispatches a background job automatically:
Override queue settings per-send:
Full queuing guide: docs/queuing.md
Events & Listeners
The package dispatches the following events:
| Event | When |
|---|---|
SmsSent |
After a successful SMS send |
SmsFailed |
When an SMS send fails |
WhatsAppSent |
After a successful WhatsApp send |
WhatsAppFailed |
When a WhatsApp send fails |
LowBalanceDetected |
When wallet balance drops below threshold |
Listening to Events
Discover All Events
Full events guide: docs/events.md
Testing
Use Fast2sms::fake() to prevent real HTTP calls in tests:
WhatsApp Assertions
Combined Assertions
Stopping the Fake
Fast2sms::fake() stores the fake in a static property. Call Fast2sms::stopFaking() in tearDown to restore real HTTP behaviour when managing the fake lifecycle manually in plain PHPUnit tests:
Note: When using Orchestra Testbench or Laravel's full boot cycle the container is re-booted between tests, so
stopFaking()is usually not required.Full testing guide: docs/testing.md
Artisan Commands
| Command | Description |
|---|---|
fast2sms:balance |
Check wallet balance and alert if below threshold |
fast2sms:waba |
Show WhatsApp Business Account details |
fast2sms:events |
List all package events |
fast2sms:ide-helper |
Generate IDE helper stub for better autocomplete (non-production only) |
Phone Validation
Use the Fast2smsPhone rule to validate Indian mobile numbers:
The rule validates 10-digit Indian mobile numbers starting with 6โ9.
Error Handling
All exceptions extend Fast2smsException, so you can catch broadly or specifically:
Exception Reference
| Exception | When |
|---|---|
ConfigurationException |
Invalid config (missing API key, bad driver) |
ValidationException |
Invalid input (empty numbers, bad phone format) |
AuthenticationException |
Invalid or missing API key (HTTP 401) |
RateLimitException |
Too many requests (HTTP 429) |
ServerException |
Fast2SMS server error (HTTP 5xx) |
ApiException |
Other API error (4xx) |
NetworkException |
Network timeout or connection failure |
DuplicateSendException |
Identical send repeated within the deduplication TTL |
InsufficientBalanceException |
Wallet balance too low when Balance Gate abort is true |
ThrottleExceededException |
Send-rate limit reached for the configured window |
Full error handling guide: docs/error-handling.md
Full API reference: docs/api-reference.md
Upgrade Guide
Upgrading from v1.x? See UPGRADING.md for the full migration guide, including:
- New exception types to catch
- Readonly DTO changes
- Fake assertion API changes
- Deprecated method renames (
content()โwithContent(),to()โwithNumbers()) - Response type-hint updates
Also available as an extended guide: docs/upgrade-v1-to-v2.md
Contributing
Contributions are welcome! Please read CONTRIBUTING.md before submitting a pull request.
License
The MIT License (MIT). Please see LICENSE.md for more information.
Made with โค๏ธ for the Laravel community · Shakil Alam
All versions of laravel-fast2sms with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/notifications Version ^11.0|^12.0|^13.0
illuminate/queue Version ^11.0|^12.0|^13.0
illuminate/events Version ^11.0|^12.0|^13.0