GitHub - merodiro/Friendships: a package for simple Friendships system

 4 years ago
source link: https://github.com/merodiro/Friendships
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Laravel 5 Friendships

This package gives users the ability to manage their friendships.

Models can:

  • Send Friend Requests
  • Accept Friend Requests
  • Deny Friend Requests
  • Delete Friend


First, install the package through Composer.

composer require merodiro/friendships

Then include the service provider inside config/app.php.

'providers' => [

Finally, migrate the database

php artisan migrate

Setup a Model

use Merodiro\Friendships\Friendable;
class User extends Model
    use Friendable;

How to use

Check the Test file to see the package in action

Send a Friend Request


Accept a Friend Request


Deny a Friend Request


Remove Friend


Mutual Friends


check the current relationship between two users


it returns

  • same_user => if the $user is checking his own account
  • friends => if they are friends
  • waiting => if $user sent a request waiting for approval from $anotherUser
  • pending => if $anotherUser user sent a request waiting for approval from $user
  • not_friends => if they are not friends

Check if two users are friends


it returns true if they are friends and false if they aren't


To get a collection of users use the following methods:

Get Friends


Get a list of users that $user has received friend requests from


Get a list of users that $user has sent friend requests to



This is the list of the events fired by default for each action

Event name Fired
friendrequest.sent When a friend request is sent
friendrequest.accepted When a friend request is accepted
friendship.deleted When a friend request is denied
friendship.deleted When a friendship is deleted

for more about how to use the events Check this example


$ composer test


Please see CONTRIBUTING and CODE_OF_CONDUCT for details.


If you discover any security-related issues, please email [email protected] instead of using the issue tracker.



The MIT License (MIT). Please see License File for more information.

About Joyk

Aggregate valuable and interesting links.
Joyk means Joy of geeK