illizian / notifications
A Laravel 4 package that provides Facebook style notifications
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is auto-updated.
Last update: 2024-10-21 16:30:39 UTC
README
A basic Laravel package that provides Facebook style notifications. Notifications are assigned to your own User model and are automatically marked as read when that User visits the URL associated with the notification.
Installation
- Add to your composer.json
$ composer require illizian/notifications
- Add the Service Provider to your config/app.php file
'providers' => array( // [...] 'Illizian\Notifications\NotificationsServiceProvider' )
- Update your User model
use Illizian\Notifications\Traits\NotificationableTrait; class User extends Eloquent { use NotificationableTrait; // [...] }
This package assumes your User model's classname is "User" - see Configuration on how to override this
- Run the package migration
$ php artisan migrate --package="illizian/notifications"
Usage
The main Class for this package will be automatically aliased to 'Notify' for you, you can then use the class in your controllers to trigger notifications for a User:
$to = User::find(1); $from = User::find(2); $msg = 'User 2 has sent you a message'; $url = '/inbox/message'; // This should be a relative URL Notify::send($to, $from, $msg, $url);
Then you can get the User's notifications from their model:
$notifications = User::find(1)->notifications;
When the User visits /inbox/message
the package will detect this and mark the notification as read, alternatively you can manually mark the notification read by providing the notification's ID to the read function:
Notify::read(1)
Routes & Views
The package contains some basic routes & views to get you started. The following routes are available:
Configuration
The package contains a basic configuration file. You can import the configuration by running:
$ php artisan config:publish illizian\notifications