liliom/unifonic-notification-channel

This package is abandoned and no longer maintained. The author suggests using the multicaret/unifonic-notification-channel package instead.

Unifonic Notification Channel for laravel.

v3.0.0 2021-06-01 18:38 UTC

This package is auto-updated.

Last update: 2021-06-01 18:38:52 UTC


README

687474703a2f2f63646e2e6d756c746963617265742e636f6d2f7061636b616765732f6173736574732f696d672f756e69666f6e69632d6c6f676f2e706e67

Unifonic notification channel for Laravel 8.x +

The Unifonic channel makes it possible to send out Laravel notifications as SMS

Total Downloads Latest Stable Version License

Installation

You can install this package via composer:

composer require multicaret/unifonic-notification-channel

The service provider gets loaded automatically.

Setting up the Unifonic service

Check out the configuration of Laravel Unifonic Library

Usage

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

Notification Example

<?php
namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Multicaret\Notifications\Messages\UnifonicMessage;

class InvoicePaid extends Notification
{
   private $message;

    /**
     * Create a new notification instance.
     *
     * @param $message
     */
    public function __construct($message)
    {
        $this->message = $message;
    }
    
    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [
            'unifonic',
        ];
    }

    /**
     * Get the text message representation of the notification
     *
     * @param  mixed $notifiable
     *
     * @return UnifonicMessage
     */
    public function toUnifonic($notifiable)
    {
        return (new UnifonicMessage())
            ->content($this->message);
    }
}

Or pass the content you want directly into the constructor

public function toUnifonic($notifiable)
{
    return new UnifonicMessage('Laravel notifications are awesome!');
}

Sending Notifications

There are two methods to send a notification in Laravel:

Method 1

Using notify() function on any model that uses Notifiable trait. to achieve this you have to feed it with the proper column to be used as the recipient number, as shown in the following example, this function is placed within the User model (You might want to write it in different model in your case, just make sure to use Notifiable)

    /**
     * Route notifications for the Unifonic channel.
     *
     * @param  \Illuminate\Notifications\Notification $notification
     *
     * @return string
     */
    public function routeNotificationForUnifonic($notification)
    {
        return $this->phone; // where phone is the column within your, let's say, users table.
    }

Method 2

Using route() static function on Notification class.

Notification::route('unifonic', 'xxxxx')
                 ->notify(
                    new \App\Notifications\InvoicePaid('Laravel notifications are awesome!')
                 );
                 // where xxxxx is the phone number you want to sent to,
                 // i.e: 1xxxxxxx - NO NEED for _00_ or _+_ 

Contributing

See the CONTRIBUTING guide.

Changelog

Please see CHANGELOG for more information about what has changed recently.