mercredi 22 juin 2016

Not been able to get view of each users. Instead it's only showing current user as follower of itself

I am building follow relationship in laravel 5.2, i've defined relationship in User Model and this is my code.

public function iamfollowing() { return $this->belongsToMany('Diskourse\Models\User','followers','user_id','followed_id');

}

public function iamfollowedBy()
{
    return $this->belongsToMany('Diskourse\Models\User','followers','followed_id','user_id');
}

public function following()
{
    return $this->iamfollowing()->get();
}

public function followers()
{  

 return $this->iamfollowedBy()->get();

}

But when i try to display the list of followers it's only displaying current user equals to number of expected followers. This is my view

    <div class="col-lg-4 col-lg-offset-3">

        <!--Followers list->

            <h4>Followers</h4>

            @if(!$user->followers()->count())

            <p>No followers</p>

            @endif
                @foreach($user->followers() as $follower)

                    @include('user/partials/userblock')

                @endforeach
            </div>
        </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire