tashkar18 / laravel-social-notification by tashkar18

Simple Notification System for Laravel 4.2
111
0
2
Package Data
Maintainer Username: tashkar18
Maintainer Contact: tashkar18@gmail.com (Tamer Ashkar)
Package Create Date: 2015-11-19
Package Last Update: 2016-04-03
Home Page:
Language: PHP
License: Unknown
Last Refreshed: 2024-11-26 15:06:34
Package Statistics
Total Downloads: 111
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Notification (Laravel 4)

Quick Start

Required Setup

Require tashkar18\notification with the composer command

$ composer require tashkar18/notification ~0.2

In your config/app.php file,

add Tashkar18\Notification\NotificationServiceProvider to the end of the providers array

  'providers' => array(
    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'Tashkar18\Notification\NotificationServiceProvider',
  ),

Now generate the configuration file

$ php artisan config:publish tashkar18/notification

Then migrate the notifications table

$ php artisan migrate --package="tashkar18/notification"

Setup

In any of your Eloquent models, implement the NotificationInterface and use the NotificationTrait.

use Tashkar18\Notification\NotificationInterface;
use Tashkar18\Notification\NotificationTrait;

class Comment extends Eloquent implements NotificationInterface
{
    use NotificationTrait;

Then implement these methods in your model.

/**
 * This determines the recipient id of the event.
 * For example, if a user comments on a post, the recipient of the
 * notification would be the post's author.
 * @return {int}
 */
public function getNotificationRecipient()
{
    return $this->post->user_id;
}

/**
 * This determines the sender id of the event.
 * For example, if a user comments on a post, the sender of the
 * notification would be the comment's author. (This will typically
 * be user_id, but you might also use a different attribute for the user_id like author_id);
 * @return {int}
 */
public function getNotificationSender()
{
    return $this->user_id;
}

You can add the NoterTrait to the your User model to setup the user hasMany relationship

use Tashkar18\Notification\NoterTrait;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait, NoterTrait;

You will then be able to access user notifications

return $user->notifications;

Configuration

Create your Notification-specific views folder, and adjust the packages/tashkar18/notification/config.php to match

  return array(
      'view' => 'notifications'
  );

Create your ViewPresenter for your Eloquent model.

Your view presenter file is simply a view file that will present your notification in human readable text.

For example, a Comment model would have a view file in views\notifications\comment.blade.php The comment object will automatically be passed into that view and can be access with the variable $comment.

// views/notifications/comment.blade.php
{{{ ucfirst($comment->user->username) }}} commented on your post.

Testing (coming soon)