fahmiardi/laravel-notification

各种 Laravel 通知渠道

0.1 2016-12-15 17:56 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:44:19 UTC


README

可用渠道

  • AWS SNS(简单通知服务),支持使用 credentialsprofile

安装

$ composer require fahmiardi/laravel-notification

设置

将配置添加到 app/services.php

return [
    ...
    'sns' => [
        'key' => env('SNS_KEY'),
        'secret' => env('SNS_SECRET'),
        'region' => env('SNS_REGION'),
        'profile' => env('AWS_PROFILE'), // keep this value empty when using credentials
    ],
];

使用方法

使用通用方式

<?php

$user->notify(
    new \Fahmiardi\Laravel\Notifications\GenericSnsNotification($topicArn, $subject, $message)
);

创建自己的

阅读官方页面 https://laravel.net.cn/docs/5.3/notifications#creating-notifications

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Fahmiardi\Laravel\Notifications\Channels\SnsChannel;
use Fahmiardi\Laravel\Notifications\Messages\SnsMessage;

class InvoicePaid extends Notification
{
    protected $invoice;

    public function __construct($invoice)
    {
        $this->invoice = $invoice;
    }

    public function via($notifiable)
    {
        return [SnsChannel::class];
    }

    public function toSns($notifiable)
    {
        return (new SnsMessage)
            ->topicArn('ARN')
            ->subject('SUBJECT')
            ->message('MESSAGE');
    }
}

$user->notify(new InvoicePaid($invoice));