Laravel Notifications

Notification package Laravel 5

This one is awesome. Painless notifications in your application. How I use it?

In my master blade template I just put notifications printing code:

@notification()

Then in my controllers I can send notifications to blade views like this:

\Notification::success('User Updated Successfully');

But… I’m lazy bastard so one secret.

Create file: app/Observers/NotificationsObserver.php

namespace App\Observers;

class NotificationsObserver
{

    /**
     * @param $model
     */
    public function updated($model)
    {
        \Notification::success(class_basename($model) . ' Updated Successfully');
    }

    /**
     * @param $model
     */
    public function created($model)
    {
        \Notification::success(class_basename($model) . ' Created Successfully');
    }

    /**
     * @param $model
     */
    public function deleted($model)
    {
        \Notification::success(class_basename($model) . ' Deleted Successfully');

    }
}

And in every model which you want to send notifications – use this observer.

class User extends Model {

protected static function boot()
    {
        parent::boot();

        self::observe(new NotificationsObserver);
    }
}

Screenshot 2016-01-31 21.27.04

Share on FacebookShare on RedditShare on Google+Tweet about this on TwitterShare on LinkedIn
don't waste your time using copy/paste, just use share buttons above
Laravel Notifications