chitranu/textlocal-laravel-notification-channel

Textlocal SMS Notification channel for Laravel

1.0.0 2020-09-27 18:34 UTC

This package is auto-updated.

Last update: 2024-10-28 04:26:18 UTC


README

Latest Version on Packagist Software License StyleCI Total Downloads

This package makes it easy to send notifications using Textlocal with Laravel framework.

Contents

Installation

You can install the package via composer:

composer require chitranu/textlocal-laravel-notification-channel

Setting up the Textlocal SMS service

Add your Textlocal API key and sender to your config/services.php:

<?php

return [

    // ...

    'textlocal' => [
        'key' => env('TEXTLOCAL_KEY'),
        'sender' => env('TEXTLOCAL_SENDER'),
    ],

];

Usage

Now you can use the channel in your via() method inside the notification:

<?php

use NotificationChannels\Textlocal\TextlocalChannel;
use NotificationChannels\Textlocal\TextlocalMessage;
use Illuminate\Notifications\Notification;

class AccountApproved extends Notification
{
    public function via($notifiable)
    {
        return [TextlocalChannel::class];
    }

    public function toSms($notifiable)
    {
        // OR explicitly return a TextlocalMessage object passing the message body:
        return new TextlocalMessage("Your {$notifiable->service} account was approved!");
    }
}

In order to let your Notification know which phone are you sending to, the channel will look for the phone, mobile, phone_number or full_phone attribute of the Notifiable model. If you want to override this behaviour, add the routeNotificationForTextlocal method to your Notifiable model.

<?php

use Illuminate\Notifications\Notifiable;

class SomeModel {
    use Notifiable;

    public function routeNotificationForTextlocal($notification)
    {
        return '+1234567890';
    }
}

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Security

If you discover any security related issues, please email hey@swapnil.dev instead of using the issue tracker.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.