PHPackages                             michaeljennings/feed - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. michaeljennings/feed

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

michaeljennings/feed
====================

A simple activity feed for laravel 5+

v0.2(9y ago)111.4k2MITPHP

Since Mar 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/michaeljennings/feed)[ Packagist](https://packagist.org/packages/michaeljennings/feed)[ RSS](/packages/michaeljennings-feed/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (8)Dependencies (6)Versions (8)Used By (0)

Feed (deprecated for Laravel 5.3+) [![Build Status](https://camo.githubusercontent.com/40fa65d6c30863394dbc6344ef4bcd1fa4730b2185ce0b4d71e9aabeb3c85060/68747470733a2f2f7472617669732d63692e6f72672f6d69636861656c6a656e6e696e67732f666565642e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/michaeljennings/feed) [![Coverage Status](https://camo.githubusercontent.com/35e2cebd665f82717afe538121645cabe6969494b05e47da99b5cec7e00af082/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d69636861656c6a656e6e696e67732f666565642f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/michaeljennings/feed?branch=master)
=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#feed-deprecated-for-laravel-53---)

> Note: This package is no longer maintaned for Laravel 5.3+ since Laravel now offers built in [notifications](https://laravel.com/docs/5.6/notifications).

A basic notification feed for laravel 5+.

Below is some example code of all of the basic methods for the package.

```
$user = User::find(1);
$team = Team::find(1);

// Push notification to a user
$feed->push('This is a new notification', $user);

// Push notification to a user, and a team of users
$feed->push('This is a new notification', [$user, $team]);

// Push notification to a user with multiple parameters
$feed->push([
    'icon' => 'icon-alert',
    'title' => 'Something Broke!',
    'body' => 'Something super important broke'
], $user);

// Get all of the notifications for a user
$notifications = $feed->pull($user);

// Get 10 notifications for the user
$notifications = $feed->limit(10)->pull($user);

// Mark a notification as read
$feed->markAsRead($notification);
```

Navigation
----------

[](#navigation)

- [Installation](#installation)
- [Configuration](#configuration)
    - [Changing the Notification Model](#changing-the-notification-model)
    - [Adding a Driver](#adding-a-driver)
- [Using the Feed](#using-the-feed)
- [Setting Up Notifiable Models](#setting-up-notifiable-models)
    - [Notifiable Groups](#notifiable-groups)
- [Available Methods](#available-methods)
    - [Push](#push)
    - [Pull](#pull)
        - [Pull Read](#pull-read)
        - [Limiting Results](#limiting-results)
        - [Offsetting Results](#offsetting-results)
        - [Paginate Results](#paginate-results)
        - [Filtering Results](#filtering-results)
        - [Get the Latest Results](#get-the-latest-results)
        - [Get the Oldest Results](#get-the-oldest-results)
        - [Putting it All Together](#putting-it-all-together)
    - [Marking Notification as Read](#marking-notification-as-read)
    - [Marking Notification as Unread](#marking-notification-as-unread)

Installation
------------

[](#installation)

This package requires at least laravel 5.

To install through composer include the package in your `composer.json`.

```
"michaeljennings/feed": "0.2.*"

```

Run `composer install` or `composer update` to download the dependencies, or you can run `composer require michaeljennings/feed`.

Once installed add the service provider to the providers array in `config/app.php`.

```
'providers' => [

  Michaeljennings\Feed\FeedServiceProvider::class

];
```

To publish the migrations and config files run `php artisan vendor:publish`.

Configuration
-------------

[](#configuration)

The package comes with a default migration to create the database structure for the package. By default this table allows for the notifications to have a body, and an icon. If need more data for your notification such as a title, we recommend adding the columns to the default migration.

The package comes with `feed.php` config file. This allows you to customise the database driver you are using with the package. At present only eloquent is supported, but we are working on a laravel db driver currently.

### Changing the Notification Model

[](#changing-the-notification-model)

From time to time you may need to add additional methods or properties to the notification model, for example you might want to add an additional relationship to the notification model.

This can be done very simply by changing the notification model in the config file as shown below.

```
'drivers' => [
    'eloquent' => [
        'model' => 'Path\To\Notification', // Update this to your notification model.
    ],
]
```

The default notification model implements a couple of interfaces that are required by this package. If you need to make changes to the model I recommend extending the default model, otherwise make sure you implement the interfaces.

```
// Example of extending the model
class Notification extends \Michaeljennings\Feed\Store\Eloquent\Notification
{
    public function foo()
    {
        //
    }
}

// Example of just implementing the interfaces
class Notification implements \Michaeljennings\Feed\Contracts\Notification, \Michaeljennings\Feed\Contracts\Store
{
    public function bar()
    {
        //
    }
}
```

### Adding a Driver

[](#adding-a-driver)

You may require another driver, i.e. you're using a data store not supported by laravel. If this is the case you can add a driver to the system verify simply as shown below.

```
// Here we grab the driver manager and then extend it to a new 'foo' driver.
// Ideally this would be done within a service provider.
app('feed.manager')->extend('foo', function($app) {
    return new Foo();
});

// The Foo driver needs to implement the Store interface so it has all of
// the necessary methods.
class Foo implements Michaeljennings\Feed\Contracts\Store
{
    //
}

// The in the config file set the driver to our new foo driver.
return [
    'driver' => 'foo'
]
```

For more information on adding drivers look at the [laravel documentation on extending the framework](https://laravel.com/docs/5.0/extending).

Using the Feed
--------------

[](#using-the-feed)

Once installed you can access the feed in multiple ways.

Firstly you can dependency inject it from the IOC container by either the push or pull feed interfaces. Both interfaces will return the same instance, it's just to make your code more readable.

```
public function __construct(
    Michaeljennings\Feed\Contracts\PullFeed $pullFeed,
    Michaeljennings\Feed\Contracts\PushFeed $pushFeed
) {
    $this->pullFeed = $pullFeed;
    $this->pushFeed = $pushFeed;
}
```

Or you there is a `feed` helper method.

```
$feed = feed();
```

Or if you want to use the facade you can register it in the aliases array in `config/app.php`.

```
'aliases' => [
    'Feed' => Michaeljennings\Feed\Facades\Feed::class
]
```

Setting Up Notifiable Models
----------------------------

[](#setting-up-notifiable-models)

To set up a notifiable model you just need to implement the notifiable interface, and then use the notifiable trait in your model.

This will set up the required relationships.

```
use Michaeljennings\Feed\Contracts\Notifiable as NotifiableContract;
use Michaeljennings\Feed\Notifications\Notifiable;

class User extends Model implements NotifiableContract
{
    use Notifiable;
}
```

### Notifiable Groups

[](#notifiable-groups)

It is also possible to set up groups of notifiable models, an example of when this would be useful is having a team of users. This will allow us to push a notification to all the members of that group.

To set up a notifiable group you need implement the notifiable group interface on the group model. This will add a method called `getGroup` which requires you to return the members you would like to be notified.

In the example below we have a team model which implements the group interface. It has a `users` relationship which returns all of the users belonging to the team. Then in the `getGroup` method we simply return the users.

```
use Michaeljennings\Feed\Contracts\NotifiableGroup;

class Team extends Model implements NotifiableGroup
{
    public function users()
    {
        return $this->hasMany('App\User');
    }

    public function getGroup()
    {
        return $this->users;
    }
}
```

Available Methods
-----------------

[](#available-methods)

Below is a list of all of the currently available notification methods. If you think of anything you want to add please feel free to create an issue, or a pull request.

### Push

[](#push)

The push method allows you to push a notification to a notifiable model, multiple notifiable models, or a notifiable group.

When pushing to a notifiable group each member of the group will get their own notification, it will not share one notification for all of the members.

```
$feed->push('My awesome notification', $user);
$feed->push('My awesome notification', [$user, $team]);
$feed->push([
    'title' => 'New Notification',
    'body' => 'My awesome notification'
], $user);
```

When the notification is pushed a `NotificationAdded` event will be fired.

You can then listen for this and then broadcast the notification, send an email etc.

You just need to register the listeners in the event service provider.

```
protected $listen = [
    'Michaeljennings\Feed\Events\NotificationAdded' => [
        'App\Listeners\BroadcastNotification',
        'App\Listeners\EmailNotification',
    ],
];
```

### Pull

[](#pull)

The pull method gets all of the unread notifications for the notifiable models you pass it.

```
$feed->pull($user);
```

#### Pull Read

[](#pull-read)

To get all of the read notifications for a member, use the `pullRead` method.

```
$feed->pullRead($user);
```

#### Limiting Results

[](#limiting-results)

To limit the amount of notifications returned when pulling, chain the `limit` method.

```
$feed->limit(10)->pull($user);
$feed->limit(10)->pullRead($user);
```

#### Offsetting Results

[](#offsetting-results)

To offset the results when pulling, chain the `offset` method. This can be useful for infinte scrollers.

```
$feed->offset(10)->pull($user);
$feed->offset(10)->pullRead($user);
```

#### Paginate Results

[](#paginate-results)

If you want to paginate the results and let laravel handle the limiting and offsetting for you, chain the `paginate` method.

```
$feed->paginate(10)->pull($user);
$feed->paginate(10)->pullRead($user);
```

#### Filtering Results

[](#filtering-results)

From time to time you may wish to run additional queries on the notification results, to do this chain the filter method.

The filter method requires a closure which is passed an instance of the query builder. In the example below we're only getting results that have an alert icon.

```
$feed->filter(function($query) {
    $query->where('icon', 'icon-alert');
})->pull($user);

$feed->filter(function($query) {
    $query->where('icon', 'icon-alert');
})->pullRead($user);
```

#### Get the Latest Results

[](#get-the-latest-results)

To order the results by the latest notification added, chain the `latest` method. By default the notifications are ordered by the latest notification added.

```
$feed->latest()->pull($user);
$feed->latest()->pullRead($user);
```

#### Get the Oldest Results

[](#get-the-oldest-results)

To order the results by the oldest notification added, chain the `oldest` method. By default the notifications are ordered by the latest notification added.

```
$feed->oldest()->pull($user);
$feed->oldest()->pullRead($user);
```

#### Putting it All Together

[](#putting-it-all-together)

All of these methods can be chained together, this should allow you to get the notifications in any way you require.

```
// Limit and offset the results
$feed->limit(10)->offset(10)->pull($user);

// Get all of the oldest read notifications, that have an alert icon.
$feed->filter(function($query) {
    $query->where('icon', 'icon-alert');
})->oldest()->pullRead($user);
```

### Marking Notification as Read

[](#marking-notification-as-read)

To mark a notification as read you can either use the `markAsRead` method, or it is aliased to `read` if you prefer.

```
$feed->markAsRead($notification);
$feed->read($notification);
```

When the notification is read marked as read a `NotificationRead` event will be fired.

You can then listen for this and then broadcast it etc.

```
protected $listen = [
    'Michaeljennings\Feed\Events\NotificationRead' => [
        'App\Listeners\BroadcastReadNotification',
    ],
];
```

### Marking Notification as Unread

[](#marking-notification-as-unread)

To mark a notification as unread you can either use the `markAsUnread` method, or it is aliased to `unread` if you prefer.

```
$feed->markAsUnread($notification);
$feed->unread($notification);
```

When the notification is read marked as unread a `NotificationUnread` event will be fired.

You can then listen for this and then broadcast it etc.

```
protected $listen = [
    'Michaeljennings\Feed\Events\NotificationUnread' => [
        'App\Listeners\BroadcastUnreadNotification',
    ],
];
```

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~22 days

Recently: every ~9 days

Total

7

Last Release

3635d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/df807d0371b1b265ea1becedfa4001428f278e7632c6d175e2afb2921f5788a3?d=identicon)[michaeljennings](/maintainers/michaeljennings)

---

Top Contributors

[![michaeljennings](https://avatars.githubusercontent.com/u/5189701?v=4)](https://github.com/michaeljennings "michaeljennings (73 commits)")[![DevKingDigital](https://avatars.githubusercontent.com/u/13821111?v=4)](https://github.com/DevKingDigital "DevKingDigital (2 commits)")

---

Tags

laravelfeedactivity

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/michaeljennings-feed/health.svg)

```
[![Health](https://phpackages.com/badges/michaeljennings-feed/health.svg)](https://phpackages.com/packages/michaeljennings-feed)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58122.8k](/packages/laracraft-tech-laravel-useful-additions)[wearepixel/laravel-cart

A cart implementation for Laravel

1355.6k](/packages/wearepixel-laravel-cart)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
