2017 © Pedro Peláez
 

library l4-notifier

Laravel user notification package

image

smartsoftware/l4-notifier

Laravel user notification package

  • Thursday, October 1, 2015
  • by msantang78
  • Repository
  • 0 Watchers
  • 0 Stars
  • 29 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Laravel User Notifications

logo3.png, (*1)

Features, (*2)

  • 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:, (*3)

    $ composer require smartsoftware/l4-notifier

Publish config file:, (*4)

    $ php artisan view:publish smartsoftware/l4-notifier

Run migrations, (*5)

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

Edit config file:, (*6)

#!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:, (*7)

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

class User extends Eloquent {

        use NotifiedTrait;

    ...
    ...
}

Create a notification type:, (*8)

To create a notification we use l4notifier:createtype command, (*9)

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:, (*10)

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, (*11)

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

Send a notification to multiple users:, (*12)

#!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, (*13)

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

The Versions

01/10 2015

dev-master

9999999-dev

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications

01/10 2015

v0.1.4

0.1.4.0

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications

11/09 2015

v0.1.3

0.1.3.0

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications

22/08 2015

v0.1.2

0.1.2.0

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications

21/08 2015

v0.1.1

0.1.1.0

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications

20/08 2015

v0.1.0

0.1.0.0

Laravel user notification package

  Sources   Download

MIT

The Requires

 

by Martin Alejandro Santangelo

laravel user notifications