renderbit/laravel-sms

Framework-agnostic PHP library for sending SMS via Renderbit, with Laravel support.

1.0.0 2025-06-05 13:04 UTC

This package is auto-updated.

Last update: 2025-06-05 13:08:17 UTC


README

A Laravel package to send transactional SMS messages through supported SMS gateways. Built with simplicity, scalability, and performance in mind.

๐Ÿš€ Features

  • Simple API to send SMS
  • Support for multiple providers (via api-based architecture)
  • Queue-friendly and retry-safe
  • Customizable sender name and API URL
  • Laravel-native configuration and logging
  • Facade & dependency injection support

๐Ÿ“ฆ Installation

Install via Composer:

composer require renderbit/laravel-sms

๐Ÿ›  Configuration

Publish the configuration file:

php artisan vendor:publish --tag=sms-config

This will publish config/sms.php.

Example config/sms.php:

return return [
    'url' => env('SMS_API_URL', '<default-preconfigured-url>'),
    'query_params' => [
        'user' => env('SMS_USER'),
        'password' => env('SMS_PASSWORD'),
        'senderid' => env('SMS_SENDER_ID', 'IEMUEM'),
        'channel' => 'trans',
        'DCS' => 0,
        'flashsms' => 0,
        'route' => '1'
    ],
    'number_field' => env('SMS_NUMBER_FIELD', 'number'),
    'message_field' => env('SMS_MESSAGE_FIELD', 'text'),
];;

Update your .env file:

SMS_USER=
SMS_PASSWORD=
SMS_SENDER_ID='IEMUEM'
SMS_API_URL='http://1.1.1.1/api/SendSMS?'
SMS_NUMBER_FIELD='number'
SMS_MESSAGE_FIELD='text'

โœ‰๏ธ Usage

You can send an SMS using the facade or the SmsClient class:

Using Facade

use Sms;

Sms::send('+919999999999', 'Hello, your OTP is 123456');

Using Dependency Injection

use Renderbit\Sms\SmsClient;

class NotificationService
{
    public function __construct(protected SmsClient $sms) {}

    public function notify($phone, $message)
    {
        $this->sms->send($phone, $message);
    }
}

โœ… Example Response Handling

The send method returns a bool:

$success = Sms::send($phoneNumber, $message);

if (!$success) {
    // Log failure or retry
}

๐Ÿงช Testing

To fake SMS sending during tests:

Sms::shouldReceive('send')
    ->once()
    ->with('+919999999999', 'Test message')
    ->andReturn(true);

๐Ÿ“ Directory Structure (Core)

  • SmsClient: Main entry point, handles sms sending logic.
  • Facades\Sms: Facade accessor for SmsClient class.
  • config\sms: Default configs that can be overridden after publishing.
  • SmsServiceProvider: Auto-discovery and binding.

๐Ÿค Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what youโ€™d like to change.

๐Ÿ“„ License

This package is open-sourced software licensed under the MIT license.

Would you like me to initialize this as a README.md file inside your package or also help with directory scaffolding like src/SmsClient.php, Contracts, etc.?