Skip to content

This package gives Eloqent models the ability to manage their friendships.

License

Notifications You must be signed in to change notification settings

elsodev/laravel-friendships

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel 5 Friendships Build Status Version Software License

This package gives Eloqent models the ability to manage their friendships. You can easily design a Facebook like Friend System.

##Models can:

  • Send Friend Requests
  • Accept Friend Requests
  • Deny Friend Requests
  • Block Another Model

Installation

First, install the package through Composer.

composer require hootlex/laravel-friendships

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

'providers' => [
    ...
    Hootlex\Friendships\FriendshipsServiceProvider::class,
    ...
];

Lastly you need to publish the migration and migrate the database

php artisan vendor:publish --provider="Hootlex\Friendships\FriendshipsServiceProvider" && php artisan migrate

Setup a Model

use Hootlex\Friendships\Traits\Friendable;
class User extends Model
{
    use Friendable;
    ...
}

How to use

Check the Test file to see the package in action

Send a Friend Request

$user->befriend($recipient);

Accept a Friend Request

$user->acceptFriendRequest($recipient);

Deny a Friend Request

$user->denyFriendRequest($recipient);

Remove Friend

$user->unfriend($recipient);

Block a Model

$user->blockFriend($recipient);

Unblock a Model

$user->unblockFriend($recipient);

Check if Model is Friend with another Model

$user->isFriendWith($recipient);

Check if Model has blocked another Model

$user->hasBlocked($recipient);

Check if Model is blocked by another Model

$user->isBlockedBy($recipient);

Get All Friends(accepted) (It returns a collection of friend models not friendships, for example User)

$user->getAllFriends();

Get Friends(accepted) with Limit

$user->getFriendsLimited($limit);
Default $limit = 0, will return all friends
Use Case
$user->getFriendsLimited(5);

This will return only 5 friends.

Get Friends(accepted) with Pagination

$user->getFriendsWithPagination($perPage);
Default $perPage = 0, will return all friends
Use Case
$friends = $user->getFriendsWithPagination(5);

This will return a paginator object. To render links

Laravel >5.0: Use ->render();
Laravel >5.2: Use ->links();
View
@foreach($friends as $friend)
	<p>{{ $friend->name }}</p>
@endforeach

{!! $friends->links() !!}

Get a single friendship

$user->getFriendship($recipient);

Get a list of all Friendships

$user->getAllFriendships();

Get a list of pending Friendships

$user->getPendingFriendships();

Get a list of accepted Friendships

$user->getAcceptedFriendships();

Get a list of denied Friendships

$user->getDeniedFriendships();

Get a list of blocked Friendships

$user->getBlockedFriendships();

Get a list of pending Friend Requests

$user->getFriendRequests();

About

This package gives Eloqent models the ability to manage their friendships.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%