0

I'm using GetStream's Laravel integration (github.com/GetStream/stream-laravel) but noticed that 'actor' is just a swappable Model. I'm trying to allow logged in users to post, but I want to allow "anonymous" (unauthenticated) users to like the post using UserAgent/fingerprint/ip/session etc.

Has anybody done something similar or know of a method to hot swap the actors or allow the actor_id in specific situations to use another model?

hannesvdvreken
  • 4,858
  • 1
  • 15
  • 17

1 Answers1

0

You should be able to use the ActivityTrait (https://github.com/GetStream/stream-laravel/blob/master/src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php) without using the activityActor method, which is called here: https://github.com/GetStream/stream-laravel/blob/master/src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php#L130.

For example:

class Model
{
    use ActivityTrait {activityActor as traitActivityActor;}

    public function activityActor()
    {
        if (/* check if authenticated user */) {
            return $this->traitActivityActor(); // Reusing the same method.
        }

        return /* some other logic to return identifier for anonymous user */;
    }
}

There are other places to hook into and adjust the functionality by this package. But I think in your case this might be the easiest for this model.

I hope this help you in the right direction.

hannesvdvreken
  • 4,858
  • 1
  • 15
  • 17