Package Data | |
---|---|
Maintainer Username: | merodiro |
Maintainer Contact: | merodiro@gmail.com (Amr) |
Package Create Date: | 2017-05-08 |
Package Last Update: | 2020-12-09 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-19 03:00:57 |
Package Statistics | |
---|---|
Total Downloads: | 9,675 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 45 |
Total Watchers: | 0 |
Total Forks: | 3 |
Total Open Issues: | 1 |
This package gives users the ability to manage their friendships.
First, install the package through Composer.
composer require merodiro/friendships
Then include the service provider inside config/app.php
.
'providers' => [
...
Merodiro\Friendships\FriendshipsServiceProvider::class,
...
];
Finally, migrate the database
php artisan migrate
use Merodiro\Friendships\Friendable;
class User extends Model
{
use Friendable;
...
}
Check the Test file to see the package in action
$user->addFriend($recipient);
$user->acceptFriend($sender);
$user->deleteFriend($sender);
$user->deleteFriend($friend);
$user->mutualFriends($anotherUser);
$user->checkFriendship($anotherUser);
it returns
same_user
=> if the $user
is checking his own accountfriends
=> if they are friendswaiting
=> 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$user->isFriendsWith($anotherUser);
it returns true
if they are friends and false
if they aren't
To get a collection of users use the following methods:
$user->friends();
$user
has received friend requests from$user->friendRequestsReceived();
$user
has sent friend requests to$user->friendRequestsSent();
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 merodiro@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.