Q:

How to get all posts from the User's subscriptions

In my application, I have setup a User model that can have subscribers and subscriptions through a pivot table called subscriptions.
public function subscribers()
{
    return $this->belongsToMany('Forum\User', 'subscriptions', 'subscription_id', 'subscriber_id');
}

public function subscriptions()
{
    return $this->belongsToMany('Forum\User', 'subscriptions', 'subscriber_id', 'subscription_id');
}

My question is, what relationship should I use to get a list of paginated Post models (belong to a User) from the User's subscriptions?

A:

You can use the whereHas method to filter based on relationships. Assuming your Post model has a user relationship defined, your code would look something like:
// target user
$user = \App\User::first();
$userId = $user->id;

// get all of the posts that belong to users that have your target user as a subscriber
\App\Post::whereHas('user.subscribers', function ($query) use ($userId) {
    return $query->where('id', $userId);
})->paginate(10);

You can read more about querying relationship existence in the documentation.

