multicaret / laravel-acquaintances

This package gives Eloquent models the ability to manage friendships (with groups), followships along with Likes, favorites..etc.
https://laravel-news.com/manage-friendships-likes-and-more-with-the-acquaintances-laravel-package
MIT License
808 stars 72 forks source link

getFriendRequests() and getPendingFriendships() seem to output the same results #87

Closed kwindo closed 1 year ago

kwindo commented 2 years ago

Hi there,

Thanks for the package. I'v been playing around with it for a while and I seem to run into some strange behaviour.

I created a FriendshipController where I want to call the Auth user's Friendships lists. The friendship requests he received and his pending requests

<?php

namespace App\Http\Controllers;

use Multicaret\Acquaintances\Models\Friendship;

class FriendshipController extends Controller
{
    public function indexRequests()
    {
        $user = Auth::user();
        $friendships = $user->getFriendRequests();

        Log::info($friendships);

        // Some Inertia stuff

    }

    public function indexPending()
    {

        $user = Auth::user();
        $friendships = $user->getPendingFriendships();

        Log::info($friendships);

        // Some Inertia stuff

    }

}

Both functions output the same results. Not sure if this is a bug or I'm missing something.

mattvb91 commented 1 year ago

Currently having the exact same issue. @mkwsra any ideas if this is a bug?

@kwindo did you manage to fix it?

kwindo commented 1 year ago

Currently having the exact same issue. @mkwsra any ideas if this is a bug?

@kwindo did you manage to fix it?

No @mattvb91 sorry. With all repsect to the creator but I found this plugin insufficiant for what I needed so I build my own.

mkwsra commented 1 year ago

Actually, you might be in need of another function in this case.

like this one getAllFriendships() perhaps?

These functions have the same characteristics and are used to filter friendships by a group you can pass a group slug, only the status you are looking for is different, so you can use them as well if you wish

getAcceptedFriendships()
getDeniedFriendships()
getBlockedFriendships()

getFriendRequests() is not taking group in consideration.

I hope this helps guys

mkwsra commented 1 year ago

Currently having the exact same issue. @mkwsra any ideas if this is a bug? @kwindo did you manage to fix it?

No @mattvb91 sorry. With all repsect to the creator but I found this plugin insufficiant for what I needed so I build my own.

Sorry for the late reply, and sorry to hear that, I understand at the same time, and if you think you can contribute that would be great!

kwindo commented 1 year ago

Sorry for the late reply, and sorry to hear that, I understand at the same time, and if you think you can contribute that would be great!

I'm sorry, my knowledge of git is rather basic. I don't really know how to contribute to a project or manage one. I did use your code as a base (sensirely hope you don't mind) but did a lot of tweaks.

I'm not an specialist developer so at this point I'm unsure if everything I changed/added is done correctly. Feel free to check the current code here https://github.com/kwindo/laravel-friendships and take what ever you think is usefull.

mkwsra commented 1 year ago

For sure I don't mind :) it's an open-source world 🤩 Thanks for sharing your repo, this way I can check it out, best of luck with your project 🙌

kwindo commented 1 year ago

Noprob, as you can see I did not add documentation but should you have a need for the controller I created in the Laravel project I'm using for developing this package you should be able to download it somewhere in this comment. FriendshipController.php.zip

mkwsra commented 1 year ago

Yes, I just did, I will see what I can enhance, thanks for using the package

mattvb91 commented 1 year ago

Thanks guys,

just for reference for anyone else heres how I ended up doing it:

    public function pendingRequests()
    {
        return auth()->user()->getFriendRequests()->each(static function(Friendship $friendship) {
            $friendship->load('sender'); //Load
            return $friendship;
        });
    }

    public function getPendingSentRequests()
    {
        return auth()->user()->getPendingFriendships()->each(static function(Friendship $friendship) {
            return $friendship;
        })->pluck('recipient');
    }