1. Go to this page and download the library: Download michaeljennings/feed library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
michaeljennings / feed example snippets
$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);
'drivers' => [
'eloquent' => [
'model' => 'Path\To\Notification', // Update this to your notification model.
],
]
// 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()
{
//
}
}
// 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'
]
public function __construct(
Michaeljennings\Feed\Contracts\PullFeed $pullFeed,
Michaeljennings\Feed\Contracts\PushFeed $pushFeed
) {
$this->pullFeed = $pullFeed;
$this->pushFeed = $pushFeed;
}
use Michaeljennings\Feed\Contracts\Notifiable as NotifiableContract;
use Michaeljennings\Feed\Notifications\Notifiable;
class User extends Model implements NotifiableContract
{
use Notifiable;
}
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;
}
}
// 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);