tashkar18 / notification
Simple Notification System for Laravel 4.2
Installs: 111
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/tashkar18/notification
Requires
- php: >=5.4.0
- illuminate/database: 4.2.*
- illuminate/support: 4.2.*
- illuminate/view: 4.2.*
Requires (Dev)
- phpspec/phpspec: 2.0.*@dev
This package is not auto-updated.
Last update: 2025-10-11 23:59:17 UTC
README
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.