PHP code example of get-stream / stream-laravel

1. Go to this page and download the library: Download get-stream/stream-laravel 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/ */

    

get-stream / stream-laravel example snippets


$app->register(\GetStream\StreamLaravel\StreamLumenServiceProvider::class);



return [
    'api_key' => 'API_KEY',
    'api_secret' => 'API_SECRET',
    'api_app_id' => 'API_APP_ID',
    'location' => 'us-east',
    'timeout' => 3,
];

$app->configure('stream-laravel');


class Pin extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;


class Pin extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function author()
    {
        return $this->belongsTo('Author');
    }

    public function activityActorMethodName()
    {
        return 'author';
    }

class Pin extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function activityExtraData()
    {
        return ['is_retweet' => $this->is_retweet];
    }

class Pin extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function activityVerb()
    {
        return 'pin';
    }


$feed = FeedManager::getUserFeed($user->id);

$timelineFeed = FeedManager::getNewsFeeds($user->id)['timeline'];
$aggregatedTimelineFeed = FeedManager::getNewsFeeds($user->id)['timeline_aggregated'];

notification_feed = FeedManager::getNotificationFeed($user->id);


class Tweet extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function activityNotify()
    {
        if ($this->isRetweet) {
            $targetFeed = FeedManager::getNotificationFeed($this->parent->user->id);
            return [$targetFeed];
        }
    }

class Follow extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function target()
    {
        return $this->belongsTo('User');
    }

    public function activityNotify()
    {
        $targetFeed = FeedManager::getNotificationFeed($this->target->id);
        return [$targetFeed];
    }

use App\Transformers\MyModelEnrichTransformer;
use GetStream\StreamLaravel\Eloquent\ActivityTrait;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    public function enrichTransformer() {
        return new MyModelEnrichTransformer();
    }
}

use GetStream\StreamLaravel\Enrich;
$feed = FeedManager::getNewsFeeds($user->id)['timeline'];
$enricher = new Enrich();
$activities = $feed->getActivities(0, 25)['results'];
$activities = $enricher->enrichActivities($activities);

$collection = new Collection();
foreach ($activities as $activity) {
    $record = [
        "actor" => $this->transformData($activity["actor"], $activity["actor"]->enrichTransformer()),
        "object" => $this->transformData($activity["object"], $activity["object"]->enrichTransformer()),
        "verb" => $activity["verb"],
        "foreign_id" => $activity["foreign_id"],
        "time" => $activity["time"],
    ];

    if (!empty($activity["target"])) {
        array_push($record, [
            "target" => $this->transformData($activity["target"], $activity["target"]->enrichTransformer()),
        ]);
    }

    $collection->push($record);
}

return response()->json($collection);


php artisan vendor:publish --provider="GetStream\StreamLaravel\StreamLaravelServiceProvider"
config/stream-laravel.php
config/stream-laravel.php

class Pin extends Eloquent {
    use GetStream\StreamLaravel\Eloquent\ActivityTrait;

    public function activityLazyLoading()
    {
        return ['user'];
    }