GithubHelp home page GithubHelp logo

Comments (2)

TechTailor avatar TechTailor commented on June 9, 2024 1

Hey,

You can use the getAllFriendships() method which returns all types of friendships.

You can then get the status of the friendship (0=Pending, 1=Accepted, 2=Denied, 3=Blocked) and eager load the sender/recipient details (username, email, etc) and the filter through the collection to display the results as desired.

A very basic way of testing the same would be -

$user = Auth::user();
$friends = $user->getAllFriendships(); 
foreach($friends as $friend)
{
    echo 'username = ' . $friend->sender->username; (or $friend->recipient->username)
	
    if($friend->status == 0)
    	echo 'status = PENDING';
    else if($friend->status == 1)
    	echo 'status = ACCEPTED';
    else if($friend->status == 2)
    	echo 'status = DENIED';
    else if($friend->status == 3)
    	echo 'status = BLOCKED';

}

Now there is a limitation here which unfortunately we cannot get fixed since it seems this package is no longer being maintained (or accepting PR's) is that the methods will return the details of the requesting user itself which leads to a mess and confusion between friend requests sent and friend requests received by the user.

Hence why I personally whenever in use of this package, run multiple loops i.e., instead of using getAllFriendships(), I make use of the combination of getAcceptedFriendships(), getDeniedFriendships(), getBlockedFriendships(), etc. (not very efficient I know, but thats what I got to work with until I can fix this with tests).

If anyone has a better way to of doing it, please share here or better create a PR.

Hope this helps.

from laravel-friendships.

elephantux avatar elephantux commented on June 9, 2024 1

Thanks @TechTailor

I was looking for exactly this: 0=Pending, 1=Accepted, 2=Denied, 3=Blocked

from laravel-friendships.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.