承接 smartsoftware/l4-notifier 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

smartsoftware/l4-notifier

最新稳定版本:v0.1.4

Composer 安装命令:

composer require smartsoftware/l4-notifier

包简介

Laravel user notification package

README 文档

README

logo3.png

Features

  • Attached object
  • Type's with templates
  • Access to Obj propierties and relations on templates
  • Callback by type to define wich users must receive the notification

Installation & configuration

With composer:

    $ composer require smartsoftware/l4-notifier

Publish config file:

    $ php artisan view:publish smartsoftware/l4-notifier

Run migrations

    $ php artisan migrate --package='smartsoftware/l4-notifier'

Edit config file:

#!php

<?php
return array(
    /**
     * User Model
     */
    'user_model' => 'User',
    /**
     * get_users id's by notification type for batch notifications
     */
    'get_users' => [
        /**
         * @param int     $type    Notification type id
         * @param mixed   $obj     Attached Object
         * @param int     $sender  User id of notification
         */
        '1' => function($type, $obj, $sender) {
            return [11,12]; // User 11 and 12 will recive notifications of type 1
        },
        '2' => function($type, $obj, $sender) {
            $users = User::whereHas('roles', function($q) {
                $q->where('name', 'someRole');
            });
            return $users; // User with role someRole will recive notifications of type 2
        }
    ]
);

Add trait to user model:

#!php
<?php
use Smartsoftware\L4Notifier\NotifiedTrait;

class User extends Eloquent {

        use NotifiedTrait;

    ...
    ...
}

Create a notification type:

To create a notification we use l4notifier:createtype command

Usage:
    l4notifier:createtype subject [body] [url]

Arguments:
    subject               Notification Subject.
    body                  Notification Body.
    url                   Notification URL.
php artisan l4notifier:createtype "#{obj.id} Ticket closed" "The ticket #{obj.id} was closed by {from.name}" "http://tickets.com/{obj.id}"

The avaiable object for templates are:

obj:  the attached object (eloquent)
from: sender user
to:   receiver user

You could access to obj propierties like this
{from.role.id}

Use

Sending notifications

To send a notification to a single user

#!php
<?php
    $ticket = Ticket::find(10);
    $user->newNotification()
         ->withType(1)
         ->regarding($ticket)
         ->from($sender_user)
         ->deliver();

Send a notification to multiple users:

#!php
<?php
use Smartsoftware\L4Notifier\BatchNotification;

    $ticket = Ticket::find(10);
    $users = [1,4,5,110,22];
    BatchNotification::notify($users, 1, $obj, $sender_user->id);

Retrieving notifications

Get current user notificatons

#!php
<?php
    $user = Auth::user();
    $notifications = $user->notifications()
                          ->unread()
                          ->with('sender')
                          ->orderBy('sent_at','desc');
         

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-19