Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tbarbugli's avatar

Stream-laravel package

Hi, A couple of weeks ago a wrote about an example app that showed how to build activity feeds and news feeds with Laravel and get-stream/stream-php.

From that experience I decided to build a Laravel package; the package allows to keep in sync model instances with user feeds (by just using a trait) and comes with some Laravel niceties (eg. a base view structure; a FeedManager facade).

I would really like to know your opinion about this; the package is available on packagist ( https://packagist.org/packages/get-stream/stream-laravel ) and on github ( https://github.com/GetStream/stream-laravel ).

Tommaso

0 likes
6 replies
Cederman's avatar

Hi! I'm trying to implement this package but I have trouble trying to use it with Laravel. I'm creating an app which organizes student events and I have a class that is called StudentEvent. Each time a user creates an event I want it to be tracked as an activity. How might I implement get-stream to do this for me?

The user which has created the event is not a relationship. But only stored as an id in the student_event table in a column named "created_by". E.g. created_by = 1.

tbarbugli's avatar

Hi guys, I fixed the links, did not notice the issue with Markdown parsing :/

@cederman I think the easiest way to do this is use the Activity trait in the StudentEvent

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

    public function activityActor()
    {
        return $this->created_by;
    }
}

With this in place, every time a StudentEvent is created, an activity will be pushed to the feed of the user that created it (and its follower feeds).

The activityActor method tells the ActivityTrait what the value for the actor field will be; is there any particular reason for you not to have a relationship defined on created_by? Feel free to contact me on my personal email if you need more details about this (tommaso@getstream.io)

Tommaso

Cederman's avatar

Thanks for the fast reply @tbarbugli! I implemented your edits but I can't confirm it is working just yet. I add a new StudentEvent but I can't confirm from the dashboard on getstream.io if It actually registers the event being created.

I tried with the following code snippet to see if I get any output (correct me if I misunderstood something):

$feed = FeedManager::getNewsFeeds(1)['flat'];
$activities = $feed->getActivities(0,25)['results'];
var_dump($activities);

However, I get an empty array as a result. Btw, user with id 1 was the creator of the same event.

Thanks in advance! Marten

ShAmy04's avatar

@tbarbugli Is there a way to configure some options to filter the activities when reading them from feeds? Say, only get activities with certain attributes from the feed?

tbarbugli's avatar

@ShAmy04 the APIs don't support filtering, you should either do that client side or split different kind of activities on separate feeds.

Please or to participate in this conversation.