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
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
use Hootlex\Friendships\Traits\Friendable;
class User extends Model
{
use Friendable;
...
}
Check the Test file to see the package in action
$user->befriend($recipient);
$user->acceptFriendRequest($recipient);
$user->denyFriendRequest($recipient);
$user->unfriend($recipient);
$user->blockFriend($recipient);
$user->unblockFriend($recipient);
$user->isFriendWith($recipient);
$user->hasFriendRequestFrom($recipient);
$user->hasBlocked($recipient);
$user->isBlockedBy($recipient);
$user->getFriendship($recipient);
$user->getAllFriendships();
$user->getPendingFriendships();
$user->getAcceptedFriendships();
$user->getDeniedFriendships();
$user->getBlockedFriendships();
$user->getFriendRequests();
$user->getFriendsCount();
$user->getFriends();
$user->getFriends($perPage = 20);
$user->getFriendsOfFriends($perPage = 20);