D
D
dentxt2018-08-20 16:50:52
Laravel
dentxt, 2018-08-20 16:50:52

Friendship confirmation in Laravel?

With how to store and display subscriptions and subscribers - I figured it out. But how to check if the subscription is mutual (friends) in my case. I've also added an "accepted" field that contains 1 by default, but I haven't been able to push this topic further.

public function followersOf()
    {
        return $this->belongsToMany(
            'App\User',
            'follows',
            'followee_id',
            'follower_id'
        )->wherePivot('accepted', '=', 1)
            ->withPivot('accepted');
    }
public function followeesOfMine()
    {
        return $this->belongsToMany(
            'App\User',
            'follows',
            'follower_id',
            'followee_id'
        )->wherePivot('accepted', '=', 1)
        ->withPivot('accepted');
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question