granada-pride/unifonic-sms

A Laravel package for integrating Unifonic SMS with the Laravel notification system.

v1.1.1 2024-08-19 00:29 UTC

This package is auto-updated.

Last update: 2025-06-28 13:59:16 UTC


README

Github All Releases

Unifonic SMS for Laravel

Unifonic SMS is a Laravel package that provides seamless integration with the Unifonic SMS service. It allows you to send SMS messages through the Unifonic platform using Laravel's native notification system. Whether you need to send OTPs, alerts, or marketing messages, this package simplifies the process by integrating directly into Laravel.

Features

  • Seamless Integration: Easily send SMS notifications through Unifonic.
  • Configurable: Adjust settings via the Laravel config system.
  • Error Handling: Full support for exception handling and logging.
  • Laravel Compatibility: Compatible with Laravel 8.x, 9.x, and 10.x.
  • Secure: Handles sensitive data securely.

Table of Contents

Installation

To get started, install the package via Composer:

composer require granada-pride/unifonic-sms

Requirements

  • PHP >= 8.0
  • Laravel >= 8.x

Configuration

After installing the package, publish the configuration file:

php artisan vendor:publish --provider="GranadaPride\UnifonicSms\UnifonicSmsServiceProvider"

This will publish a unifonic.php configuration file to your config directory where you can set your AppSid, SenderID, and Endpoint.

Configuration Options

Example configuration (config/unifonic.php):

return [
    'appsId' => env('UNIFONIC_APP_SID', 'your-app-sid'),
    'senderId' => env('UNIFONIC_SENDER_ID', 'your-sender-id'),
    'endpoint' => env('UNIFONIC_ENDPOINT', 'https://el.cloud.unifonic.com/rest/SMS/messages'),
];

To enable logging for the Unifonic SMS package, you can add a custom log channel in your config/logging.php file:

'channels' => [
    // Other log channels...

    'unifonic' => [
        'driver' => 'single',
        'path' => storage_path('logs/unifonic.log'),
        'level' => 'error',
    ],
],

This configuration ensures that Unifonic SMS logs are stored in a separate log file at storage/logs/unifonic.log and only logs messages with a severity level of error or higher.

Usage

After configuring the package, you can send SMS notifications:

use GranadaPride\UnifonicSms\Notifications\UnifonicSmsNotification;

$phone = '1234567890';
$message = "Your verification code is 123456";

$user->notify(new UnifonicSmsNotification($phone, $message));

Advanced Usage

To customize the SMS further or handle different scenarios, you can modify the notification class:

use GranadaPride\UnifonicSms\Notifications\UnifonicSmsNotification;

class CustomSmsNotification extends UnifonicSmsNotification
{
    public function toSms($notifiable)
    {
        return [
            'phone' => $this->phone,
            'message' => "Your custom message",
        ];
    }
}

// Sending the custom SMS
$user->notify(new CustomSmsNotification($phone, $message));

Contributing

Contributions are welcome! Please feel free to submit a Pull Request or open an issue to improve this package.

License

This package is open-source software licensed under the MIT License. Please see the License File for more information.