nathangross
3 days ago

Get Users from a collection of Follows

Posted 3 days ago by nathangross

I have a Follow model

    public function location(): BelongsTo
    {
        return $this->belongsTo(Location::class);
    }

    public function sport(): BelongsTo
    {
        return $this->belongsTo(Sport::class);
    }

   public function user(): BelongsTo
   {
       return $this->belongsTo(User::class);
   }

I have a Followable trait with the following method:

public function follows(): HasMany
    {
        return $this->hasMany(Follow::class);
    }

I want to be able to send a notification to everyone who follows a location. I know how to get a collection of follows (which gives me a user_id of each) but how do I get a collection of users from that follows collection?

Please sign in or create an account to participate in this conversation.