<commit_before># Feed [![Build Status](https://travis-ci.org/michaeljennings/feed.svg?branch=master)](https://travis-ci.org/michaeljennings/feed) [![Coverage Status](https://coveralls.io/repos/github/michaeljennings/feed/badge.svg?branch=master)](https://coveralls.io/github/michaeljennings/feed?branch=master)

A basic notification feed for laravel 5+.

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

```php
$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

- [Installation](#installation)
- [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

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`.

```php
'providers' => [

  Michaeljennings\Feed\FeedServiceProvider::class

];
```

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

## 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.
 
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.

```php
// Here we grab the driver manager and then extend it to a new 'foo' driver.
// Ideally this would be done within a service provider. <commit_msg>Add configuration section to readme<commit_after># Feed [![Build Status](https://travis-ci.org/michaeljennings/feed.svg?branch=master)](https://travis-ci.org/michaeljennings/feed) [![Coverage Status](https://coveralls.io/repos/github/michaeljennings/feed/badge.svg?branch=master)](https://coveralls.io/github/michaeljennings/feed?branch=master)

A basic notification feed for laravel 5+.

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

```php
$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

- [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

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`.

```php
'providers' => [

  Michaeljennings\Feed\FeedServiceProvider::class

];
```

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

## 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 
 
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.
 
```php
'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.

```php
// 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
 
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.

```php
// Here we grab the driver manager and then extend it to a new 'foo' driver.
// Ideally this would be done within a service provider. 
{'fraction_non_alphanumeric': 0.11214249874560964, 'fraction_numerical': 0.002508780732563974, 'mean_word_length': 4.008165829145729, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 28, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '33630', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2174, 'n_words': 859}