websms/laravel-notification

There is no license information available for the latest version (1.0.0) of this package.

WebSms Laravel Notification

Installs: 11 771

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 2

Open Issues: 0

Type:laravel-package

1.0.0 2019-09-28 06:45 UTC

This package is auto-updated.

Last update: 2024-09-28 18:21:29 UTC


README

WebSms Laravel Notification

Installation

You can install the package via composer:

$ composer require websms/laravel-notification

You must install the service provider:

// config/app.php
'providers' => [
    ...
    Websms\LaravelNotification\WebSmsServiceProvider::class,
]

Setting up your WebSms account

Add your WebSms Username, Password and Sender Number to your config/services.php:

// config/services.php

...
'websms' => [
'username' => env('WEBSMS_USERNAME'),
'password' => env('WEBSMS_PASSWORD'),
'sendNumber' => env('WEBSMS_SENDNUMBER'),
],
...
// .env

WEBSMS_USERNAME=your_username
WEBSMS_PASSWORD=your_password
WEBSMS_SENDNUMBER=send_number

Usage

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

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

/**
 * Get the sms representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return string
 */
public function toSms($notifiable)
{
    $webSmsMessage = new WebSmsMessage();
    $webSmsMessage->setFrom(env('WEBSMS_SENDNUMBER'));
    $webSmsMessage->setTo($notifiable->routeNotificationFor('sms'));
    $webSmsMessage->setMessage($this->message);

    return $webSmsMessage;
}

In order to let your Notification know which phone number you are sending to, add the routeNotificationForSms method to your Notifiable model e.g your User Model

public function routeNotificationForSms()
{
    return $this->phone; // where `phone` is a field in your users table;
}

Conterbuter