hootlex / laravel-friendships

This package gives Eloquent models the ability to manage their friendships.
MIT License
706 stars 151 forks source link

Why getFriends method returns all friends ? #144

Open roshani3110 opened 3 years ago

roshani3110 commented 3 years ago

Hello,

Requirement :- to fetch friends of a specific group and I have used getFriends($perPage = 20, $group_name) method.

Problem :- getFriends($perPage = 20, $group_name) returns all friends of application and also getFriendsCount($group_name) returns count of all friends of application. can you please help me?

Here is code:

foreach ($groups as $group) { $group_name = $group->title; $group_connections = $user->getFriends($perPage = 20, $group_name); }

Thanks in advance!

TechTailor commented 3 years ago

Hey,

Can you share your group model & migration and the config/friendships.php file.

-TT

roshani3110 commented 3 years ago

config/friendships.php

`<?php

return [

'tables' => [
    'fr_pivot' => 'connections',
    'fr_groups_pivot' => 'user_connection_groups'
],

'groups' => [
    'acquaintances' => 0,
    'close_friends' => 1,
    'family' => 2
]

];`

Migration:-

`class CreateFriendshipsGroupsTable extends Migration {

public function up() {

    Schema::create(config('friendships.tables.fr_groups_pivot'), function (Blueprint $table) {

        $table->integer('friendship_id')->unsigned();
        $table->morphs('friend');
        $table->integer('group_id')->unsigned();

        $table->foreign('friendship_id')
            ->references('id')
            ->on(config('friendships.tables.fr_pivot'))
            ->onDelete('cascade');

        $table->unique(['friendship_id', 'friend_id', 'friend_type', 'group_id'], 'unique');

    });

}

public function down() {
    Schema::dropIfExists(config('friendships.tables.fr_groups_pivot'));
}

}`

TechTailor commented 3 years ago

Does the group title you are retrieving from $group->title match the group names used in the config/friendship.php file?

-TT

roshani3110 commented 3 years ago

nope, also i tried this -> $user->getFriends($perPage = 20, 'family'); but didn't work. it returns empty array.

and one question - Does this package supports a 6.8 laravel version and 7.2 php version?