Skip to content

musonza/laravel-activity-streams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel Activity Streams

Table of Contents

Click to expand

Introduction

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();

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();

What makes a valid Actor?

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

Get supported verbs

$verbs = ActivityStreams::verbs();

Add an activity to a Feed

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

Configuration

FAQ

See more on Activity Streams specifications here

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages