junityco/laravel-nowsms

This package is abandoned and no longer maintained. No replacement package was suggested.

NowSMS service provider for Laravel

1.1 2018-02-06 13:07 UTC

This package is not auto-updated.

Last update: 2023-03-26 01:14:13 UTC


README

This package makes it easy to send NowSMS notifications with Laravel.

Total Downloads Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require junityco/laravel-nowsms

Add the service provider to config/app.php in the providers array.

Junity\NowSms\NowSmsServiceProvider::class

If you want you can use the facade. Add the reference in config/app.php to your aliases array.

'NowSms' => Junity\NowSms\Facades\NowSms::class

You will also need to install guzzlehttp/guzzle http client to send requests.

Setting up your NowSMS account

Add your NowSMS url, username, password config/services.php:

// config/services.php
...
'nowsms' => [
    'url' => 'http://127.0.0.1:8800',
    'username' => '',
    'password' => '',
],
...

Usage

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

use Junity\NowSms\Messages\SmsMessage;
use Junity\NowSms\Channels\NowSmsChannel;
use Illuminate\Notifications\Notification;

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

    public function toNowSms($notifiable)
    {
        return (new SmsMessage)
            ->from("SenderID")
            ->content("Your account was approved!");
    }
}

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

public function routeNotificationForNowsms()
{
    return '+1234567890';
}

Example using via code

use Junity\NowSms\Facades\NowSms;

NowSms::send([
    'Text' => 'Some text',
    'Sender' => 'MyApp',
], '+1234567890');