Coder Social home page Coder Social logo

laravel-activity-streams's Introduction

Build Status

Laravel Activity Streams

Table of Contents

Click to expand

Introduction

This package enables you to have activity streams in your laravel applications.

Installation

Install with composer

composer require musonza/laravel-activity-streams

Once the composer installation is finished, you can add alias for the facade. Open config/app.php, and make the following update:

  1. Add a new item to the aliases array:

    'ActivityStreams' => Musonza\ActivityStreams\ActivityStreamsFacade::class,
  2. Publish the configuration file into your app's config directory, by running the following command:

    php artisan vendor:publish --tag="activity.streams.config"
    
  3. Publish the migrations into your app's migrations directory, by running the following command:

    php artisan vendor:publish --tag="activity.streams.migrations"
    
  4. Run the migrations:

    php artisan migrate
    

Usage

Facade

Whenever you use the ActivityStreams facade in your code, remember to add the following line to your namespace imports:

use ActivityStreams;

Giving a model an ability to have a Feed

Use the HasFeed trait to allow a model to have a feed.

<?php

use Illuminate\Database\Eloquent\Model;
use Musonza\ActivityStreams\Traits\HasFeed;

class User extends Model
{
    use HasFeed;
}

Create a model Feed

After adding the HasFeed trait you can create a feed for the Model as follows

$feed = $user->createFeed();

On-Demand Feeds

Sometimes you may want to create a Feed that's does not belong to a Model. For example, you want to add activities to a Trending Feed for your application:

Create a class to represent the Trending feed under a namespace of choice

<?php

namespace App;

class Trending
{
    // Optional implementation
}

Then run an artisan command that ships with the package

php artisan streams:make:feed 'App\Trending' 'some-unique-id'

some-unique-id is unique with respect to $table->unique(['some-unique-id', 'App\Trending']);

Create an Activity

An example of an activity will be something like John liked a photo in 2018Album

Actor John
Verb like
Object photo
Target 2018Album
use ActivityStreams;
use Musonza\ActivityStreams\ValueObjects\Verbs;

$activity = ActivityStreams::setActor($actor)
    ->setVerb(Verbs::VERB_LIKE)
    ->setObject($object)
    ->setTarget($target)
    ->createActivity();

Actors

Valid Actors

You can pass in an Eloquent Model as an actor or any Object that implements Musonza\ActivityStreams\Contracts\ActivityActor interface

Targets

Valid Targets

You can pass in an Eloquent Model as a target or any Object that implements Musonza\ActivityStreams\Contracts\ActivityTarget interface

Objects

Valid Objects

You can pass in an Eloquent Model as an object or any Object that implements Musonza\ActivityStreams\Contracts\ActivityObject interface

Get supported verbs

$verbs = ActivityStreams::verbs();

Add an activity to a Feed

ActivityStreams::addActivityToFeed($feed, $activity);

Add multiple activities to a Feed

Adds a Collection of activities to a Feed

ActivityStreams::addActivityToFeed($feed, $activities);

Add an activity to multiple Feeds

Adds an Activity to a Collection feeds

ActivityStreams::addActivityToMultipleFeeds($feeds, $activity);

Events

You can leverage and listen for the following events to perform actions in your application. For instance you can listen for an ActivityCreated event and depending on your business logic add the created event to a Feed or multiple feeds.

ActivityCreated

Musonza\ActivityStreams\Models\Activity\ActivityCreated

ActivityDeleted

Musonza\ActivityStreams\Models\Activity\ActivityDeleted

FeedCreated

Musonza\ActivityStreams\Models\Activity\FeedCreated

FeedDeleted

Musonza\ActivityStreams\Models\Activity\FeedDeleted

Configuration

FAQ

See more on Activity Streams specifications here

laravel-activity-streams's People

Contributors

abrahampe avatar hakanersu avatar musonza avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.