This guide provides a detailed walkthrough for migrating from Laravel Fast2SMS v1.x to v2.0. For a quick summary, see UPGRADING.md.
| Area | v1.x | v2.0 |
|---|---|---|
| Exception base | Fast2smsException only |
Full hierarchy (Auth, RateLimit, etc.) |
| DTOs | Mutable classes | readonly class — immutable |
| Fake assertions | assertSent() (generic only) |
assertSmsSent(), assertSmsNotSent(), etc. (typed); assertSent() still exists as a low-level generic method |
SmsMessage::content() |
Active method | Deprecated → use withContent() |
SmsMessage::route() |
Active method | Deprecated → use withRoute() |
SmsMessage::to() |
Active method | Deprecated → use withNumbers() |
composer require itxshakil/laravel-fast2sms:^2.0
v2.0 introduces a typed exception hierarchy. Update your catch blocks to use specific exception types:
Before (v1.x):
use Shakil\Fast2sms\Exceptions\Fast2smsException;
try {
Fast2sms::quick(...);
} catch (Fast2smsException $e) {
// handle all errors
}
After (v2.0):
use Shakil\Fast2sms\Exceptions\AuthenticationException;
use Shakil\Fast2sms\Exceptions\Fast2smsException;
use Shakil\Fast2sms\Exceptions\RateLimitException;
try {
Fast2sms::quick(...);
} catch (AuthenticationException $e) {
// 401 — bad API key
} catch (RateLimitException $e) {
// 429 — slow down
} catch (Fast2smsException $e) {
// everything else
}
Catching
Fast2smsExceptionstill works as a catch-all — no change required if you prefer broad handling.
DTOs are now readonly class. You can no longer mutate properties after construction:
Before (v1.x):
$params = new SmsParameters(...);
$params->message = 'Updated message'; // worked in v1
After (v2.0):
// Create a new instance instead
$params = new SmsParameters(message: 'Updated message', ...);
The fake API has been completely rewritten with typed, descriptive assertion methods:
Before (v1.x):
Fast2sms::assertSent(); // only generic method available
Fast2sms::assertNotSent(); // generic — no typed channel variants
After (v2.0):
// SMS-specific (new in v2)
Fast2sms::assertSmsSent();
Fast2sms::assertSmsNotSent();
Fast2sms::assertSmsSentTo('9876543210');
Fast2sms::assertSmsSentWithMessage('OTP');
Fast2sms::assertSmsSentCount(1);
// Combined
Fast2sms::assertNothingSent();
Fast2sms::assertSentCount(2);
// Low-level generic (still available in v2) — closure receives raw array payload
Fast2sms::assertSent(fn (array $message) => $message['numbers'] === ['9876543210']);
assertSent()survived into v2 as a low-level escape hatch that accepts a closure for custom assertions across both SMS and WhatsApp sends.assertNotSent()also survived into v2 as a generic counterpart — useassertSmsNotSent()orassertWhatsAppNotSent()for typed, channel-specific assertions.
The old fluent methods are deprecated and will be removed in v3.0.0:
| Deprecated | Replacement |
|---|---|
->content('...') |
->withContent('...') |
->route(SmsRoute::QUICK) |
->withRoute(SmsRoute::QUICK) |
->to('9876543210') |
->withNumbers('9876543210') |
Before (v1.x):
SmsMessage::create('Hello')
->content('Hello')
->route(SmsRoute::QUICK)
->to('9876543210');
After (v2.0):
SmsMessage::create('Hello')
->withRoute(SmsRoute::QUICK)
->withNumbers('9876543210');
Fast2sms facade and core method signatures (quick(), otp(), dlt(), whatsapp(), etc.)SmsChannel notification channelFast2smsPhone validation rulev2.0 ships six opt-in features to reduce unnecessary API calls and protect your SMS budget. They are all disabled by default and require no changes to existing code.
| Feature | Config key | Env variable | Exception |
|---|---|---|---|
| Recipient deduplication | fast2sms.recipients.deduplicate |
FAST2SMS_DEDUP_RECIPIENTS |
— |
| Invalid recipient stripping | fast2sms.validation.strip_invalid_recipients |
FAST2SMS_STRIP_INVALID |
ValidationException |
| Idempotency / dedup guard | fast2sms.deduplication.enabled |
FAST2SMS_DEDUP_ENABLED |
DuplicateSendException |
| Send-rate throttle | fast2sms.throttle.enabled |
FAST2SMS_THROTTLE_ENABLED |
ThrottleExceededException |
| Balance gate | fast2sms.balance_gate.enabled |
FAST2SMS_BALANCE_GATE |
InsufficientBalanceException |
| Batch splitting | fast2sms.recipients.batch_size |
FAST2SMS_BATCH_SIZE |
— |
New exception classes to catch (all extend Fast2smsException):
Shakil\Fast2sms\Exceptions\DuplicateSendExceptionShakil\Fast2sms\Exceptions\InsufficientBalanceExceptionShakil\Fast2sms\Exceptions\ThrottleExceededExceptionSee Cost-Saving Features for full documentation, config keys, env variables, and usage examples.
How can I help you explore Laravel packages today?