multicaret/unifonic-notification-channel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

multicaret/unifonic-notification-channel

最新稳定版本:v3.0.0

Composer 安装命令:

composer require multicaret/unifonic-notification-channel

包简介

Unifonic Notification Channel for laravel.

README 文档

README

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.

统计信息

  • 总下载量: 2.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-22