nextsms/laravel

This package makes it easy to send notifications via NextSMS with Laravel

v0.0.7 2022-05-15 23:32 UTC

This package is auto-updated.

Last update: 2024-05-16 04:10:49 UTC


README

Latest Version on Packagist Software License PHPUnit tests

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

Contents

About

The NextSMS channel makes it possible to send out Laravel notifications as SMS using NextSMS API.

Laravel compatibly

Package is Laravel v8 compatible

Laravel Version Package Version Notes
v7 or v8 dev-main Latest version
v6 6.0.x-dev
v5 5.x-dev

Installation

You can install this package via composer:

This will install the latest version

composer require nextsms/laravel

To install previous version of the package eg: version 6.0.x-dev compatible with laravel v6 see

composer require nextsms/laravel:6.0.x-dev

The service provider gets loaded automatically.

Setting up the NextSMS service

You will need to Register.

Remember to add your Sender ID that you will be using to send the messages.

NEXTSMS_USERNAME=""
NEXTSMS_PASSWORD=""
NEXTSMS_FROM=""
NEXTSMS_ENVIROMENT="production"

You can publish the package configuration file:

php artisan vendor:publish --provider="NotificationChannels\NextSms\NextSmsServiceProvider" --tag="config"

Add the routeNotifcationForNextSms method on your notifiable Model. If this is not added, the phone_number field will be automatically used.

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * Route notifications for the NextSMS channel.
     *
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return string
     */
    public function routeNotificationForNextSms($notification)
    {
        return $this->phone;
    }
}

Usage

To use this package, you need to create a notification class, like NewsWasPublished from the example below, in your Laravel application. Make sure to check out Laravel's documentation for this process.

<?php

use NotificationChannels\NextSms\NextSmsChannel;
use NotificationChannels\NextSms\NextSmsMessage;

class NewsWasPublished extends Notification
{

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [NextSmsChannel::class];
    }

    public function toNextSms($notifiable)
    {
        return (new NextSmsMessage())
                    ->content('Your SMS message content');

    }
}

Alternative usage

This packages comes with a Facade portating the NextSmsService this is usefull of you onyl want to send SMS without dealing the the Laravel Notification system

See full list of API avaliable

// import this 

use NotificationChannels\NextSms\NextSmsFacade as NextSms;

// in your controller
NextSms::singleDestination([
    'from' => 'NEXTSMS',
    'to' => '255716718040',
    'text' => 'Your message'
]);

Testing

composer test

Security

If you discover any security-related issues, please email alphaolomi at gmail.com 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.

How do I say Thank you?

Leave a ⭐ star and follow me on Twitter .