ibnnajjaar/dhiraagu-sms-laravel
Composer 安装命令:
composer require ibnnajjaar/dhiraagu-sms-laravel
包简介
A simple, lightweight package for sending SMS using Dhiraagu SMS API
README 文档
README
A simple, lightweight package for sending SMS via new Dhiraagu SMS API.
Requirements
- PHP 8.4 or higher
- Laravel 12.x or higher
- Composer
Installation
Install the package using Composer:
composer require ibnnajjaar/dhiraagu-sms-laravel
You can optionally publish configuration file
php artisan vendor:publish --tag=dhiraagu_sms
Setup & Configuration
Environment Setup
Before using the package, you need to obtain credentials (username and password) from the Dhiraagu Bulk SMS portal and add them to your environment variables:
DHIRAAGU_SMS_USERNAME=your_username DHIRAAGU_SMS_PASSWORD=your_password #DHIRAAGU_SMS_DEV_MOBILE_NUMBER=your_dev_mobile_number
[!NOTE] You can also add the dev mobile number to your environment variables. This is useful for testing purposes when you don't want to send SMS to real recipients during development. When this variable is set, all SMS will be sent to the specified dev mobile number instead of the actual recipients. This can be used when you do not have a separate testing account.
Usage
Sending SMS to Multiple Recipients
When sending SMS to multiple recipients, first create a DhiraaguSMSData object with the recipient list and message:
use IbnNajjaar\DhiraaguSMSLaravel\DataObjects\DhiraaguSMSData; // Option 1: Using the fromArray method $data = DhiraaguSMSData::fromArray([ 'recipients' => '7xxxxxx, +9607xxxxxx, 9xxxxxx', // string of recipients separated by comma 'message' => 'Hello World', // message to be sent ]); // Option 2: Using fluent methods $data = new DhiraaguSMSData() ->setRecipients('7xxxxxx, +9607xxxxxx, 9xxxxxx') ->setMessage('Hello World');
Then, to send the SMS, use the DhiraaguSMS class.
use IbnNajjaar\DhiraaguSMSLaravel\DhiraaguSMS; app(DhiraaguSMS::class)->send($data);
Sending SMS to a Single Recipient
For convenience, you can send SMS to a single recipient without creating a data object: Note: This uses a get method to send the SMS.
app(DhiraaguSMS::class)->sendToSingleRecipient($data);
Development/testing: override recipients with alwaysSendTo
In development or testing, you can force all outgoing SMS to be delivered to specific numbers, ignoring the recipients provided in your data. This helps prevent accidentally sending messages to real users.
Using DhiraaguSMS::alwaysSendTo You can define or clear an override at runtime. The override applies only when the optional condition is true.
Signature:
public static function DhiraaguSMS::alwaysSendTo(?string $recipients, bool|Closure $condition = true): void
The below examples show how to use this method. You can define the override in your service provider's register method.
use IbnNajjaar\DhiraaguSMSLaravel\DhiraaguSMS; // Always send to a single number DhiraaguSMS::alwaysSendTo('9609876543'); // Always send to multiple numbers (comma-separated) DhiraaguSMS::alwaysSendTo('9609876543,9607654321'); // Apply only in local environment (boolean condition) DhiraaguSMS::alwaysSendTo('9609876543', app()->environment('local')); // Apply only in staging (Closure condition) DhiraaguSMS::alwaysSendTo('9609876543', fn () => app()->environment('staging')); // Clear the override (reverts to config fallback, if set) DhiraaguSMS::alwaysSendTo(null); // or pass an empty string // You can also completely clear any override (including config fallback effect at runtime) \IbnNajjaar\DhiraaguSMSLaravel\DhiraaguSMS::clearAlwaysSendTo();
Notes:
- Recipients passed to alwaysSendTo are normalized and deduplicated, just like regular recipients. Invalid numbers are removed.
- When an override is active, SendMessageToMultipleRecipients will use the full override array as the destination; SendMessageToSingleRecipient will use only the first override number.
- If you do not call alwaysSendTo and have DHIRAAGU_SMS_DEV_MOBILE_NUMBER configured, that config value will be used automatically as an override.
- You may call alwaysSendTo from your own service provider's register method if you prefer centralized setup.
Using Dependency Injection
The DhiraaguSMS class is registered as a singleton, so you can use dependency injection in your services:
use IbnNajjaar\DhiraaguSMSLaravel\DhiraaguSMS; use IbnNajjaar\DhiraaguSMSLaravel\DataObjects\DhiraaguSMSData; class NotificationService { public function __construct(private DhiraaguSMS $dhiraaguSMS) { } public function handle(DhiraaguSMSData $data) { $this->dhiraaguSMS->send($data); } }
Security Considerations
Credential Management
- Store credentials in environment variables
- Never commit credentials to version control
- Add .env to your .gitignore file
Testing
composer test
Test Coverage
You can generate a coverage report without requiring Xdebug or PCOV by running tests under phpdbg via the provided Composer script:
composer test-coverage
This will execute Pest with code coverage enabled and write a Clover report to coverage.xml. If you prefer to run Pest directly, ensure you have a coverage driver installed/enabled (e.g., Xdebug with XDEBUG_MODE=coverage):
XDEBUG_MODE=coverage vendor/bin/pest --coverage
Changelog
See CHANGELOG.md for release notes: CHANGELOG.md
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Contributors
Support
For questions, issues, or feature requests, please open an issue on GitHub.
Alternatives
- Dhiraagu SMS by dash8x - A framework-agnostic PHP library for sending SMS via the Dhiraagu SMS API. This is the most popular package for integrating with the Dhiraagu SMS service.
License
This package is open-sourced software licensed under the MIT License.
ibnnajjaar/dhiraagu-sms-laravel 适用场景与选型建议
ibnnajjaar/dhiraagu-sms-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sms」 「notification」 「laravel」 「dhiraagu」 「ibnnajjaar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ibnnajjaar/dhiraagu-sms-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ibnnajjaar/dhiraagu-sms-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ibnnajjaar/dhiraagu-sms-laravel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Apple Push Notification & Feedback Provider
Throttle notifications on a per-channel basis
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Extensible library for building notifications and sending them via different delivery channels.
Simple javascript toast notifications
统计信息
- 总下载量: 96
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-20