Skip to content
Maxime Briet edited this page Aug 5, 2015 · 10 revisions

##Getting Started##

In this section we are going to see quick overview of Notifynder base components such as Categories and Builder.

####Quick Overview####

The first step to use Notifynder is to understand the easy responsibility of the categories. The categories are like the body of the notification, they are unique by a name and they hold the actual text of the notification. Every notification must have a category attached to it, (they will make your notifications more organised).

So first step is to create your first category. While you are developing you'll probably want to have a short way to create one. Notifynder has an artisan command for it:

php artisan notifynder:create:category "name.category" "Text of your category"

Now your database is populated with a new category!

Tip: I strongly suggest to namespace your categories if the amount of categories is higher then 10. That's because it will just help you to keep clean and organised your intention. Quick example: If i have X number of notifications that are targeting the user, then namespace it user.follow or user.alert etc...


Implementation

First step is to append the relations to our Model/s that you want it to be notified. For do that implement the following trait: Fenos\Notifynder\Notifable.

use Fenos\Notifynder\Notifable;

class User extends Model
{

   use Notifable;

}

Now your Model entity is able to work with notifications as the following (more methods available on the trait take at look at it: Notifable

$user = User::find(1);

$user->getNotifications($limit = null, $paginate = null, $order = 'desc');
$user->getNotificationsNotRead($limit = null, $paginate = null, $order = 'desc');
$user->getLastNotification();
$user->countNotificationsNotRead($category = null);
$user->readAllNotifications();

Note: If you don't want to use the Trait methods to manage your notifications, you can use Notifynder it self to handle manually the process. Both the way are acceptable depending your app design.

Tip: You can implement the Notifable trait in multiple models, They can notify between each other, if you do that use Notifynder as polymorphic (config/notifynder.php), use also entity('ModelNamespace') method to define the entity when sending the notification.

Next: Sending Notifications

Clone this wiki locally