Unmaintained
This package is unmaintained and was only a quick hacking around. Don't use in production code., (*1)
Friends (Laravel 5 Package)
, (*2)
Organise Friends and Relationships Between Users in Laravel and Lumen.
Friends provides everything you need to easily implement your own Facebook like Friend System.
Users can:
- Send Friend Requests
- Accept Friend Requests
- Deny Friend Requests
- Delete Friends
Contents
, (*3)
Installation
For Laravel 5.*
Pull in Package with Composer
composer require arubacao/friends
, (*4)
Register Service Provider
Include the service provider inside config/app.php
., (*5)
'providers' => [
...
Arubacao\Friends\FriendsServiceProvider::class,
...
];
Run Migrations
Publish the migration and migrate the database, (*6)
php artisan vendor:publish --provider="Arubacao\Friends\FriendsServiceProvider"
php artisan migrate
After the migration, 1 new table will be created:, (*7)
The vendor:publish
command will also create a friends.php
file in your config directory.
The default configuration should work just fine for most applications.
Otherwise check out Configuration., (*8)
Prepare User Model
Include Friendable
Trait in User
Model, (*9)
use Arubacao\Friends\Traits\Friendable;
class User extends Model
{
use Friendable; // Add this trait to your model
...
}
And you are ready to go., (*10)
, (*11)
Configuration
Configuration File friends.php
(Optional)
Find friends.php
in your config folder. Make sure you published the package beforehand., (*12)
-
user_model
— This is the applications User
model used by Friends.
-
users_table
— This is the applications users
table name used by Friends.
, (*13)
Usage
, (*14)
Friend Requests
, (*15)
Send Friend Request
$user->sendFriendRequestTo($recipient);
$user
must be instance of User
$recipient
must be instance of User
, User
array or integer (User id), (*16)
, (*17)
Accept Friend Request
$user->acceptFriendRequestFrom($sender);
$user
must be instance of User
$sender
must be instance of User
, User
array or integer (User id), (*18)
, (*19)
Deny Friend Request
$user->denyFriendRequestFrom($sender);
$user
must be instance of User
$sender
must be instance of User
, User
array or integer (User id), (*20)
, (*21)
My Friends
, (*22)
Delete Friend
$user->deleteFriend($douchebag);
$user
must be instance of User
$douchebag
must be instance of User
, User
array or integer (User id), (*23)
, (*24)
Retrieve Friends
- Get all friends of a user
-
status
is always 1
ACCEPTED
$friends = $user->friends();
$user
must be instance of User
, (*25)
$friends
:, (*26)
[{
"id": 3,
"name": "harri121",
"created_at": "2016-06-18 19:08:45",
"updated_at": "2016-06-18 19:08:45",
"pivot": {
"sender_id": 1,
"recipient_id": 3,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 22:56:40",
"status": 1
}
}]
, (*27)
Retrieve Incoming Friends
- Get all users who send friend request to
$user
-
status
is always 0
PENDING
-
recipient_id
is always id
of $user
$friends = $user->incoming_friends();
$user
must be instance of User
, (*28)
$friends
:, (*29)
[{
"id": 3,
"name": "ejoebstl",
"created_at": "2016-06-18 19:08:45",
"updated_at": "2016-06-18 19:08:45",
"pivot": {
"sender_id": 3,
"recipient_id": 1,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 22:56:40",
"status": 0
}
}]
, (*30)
Retrieve Any Friends
Remember:, (*31)
Just like in the real life a 'friend' or 'friendship' can be anything, also negative ;), (*32)
- Get all users who have any kind of friendship/relationship with
$user
$friends = $user->any_friends();
$user
must be instance of User
, (*33)
$friends
:, (*34)
[{
"id": 3,
"name": "harri121",
"created_at": "2016-06-18 19:08:45",
"updated_at": "2016-06-18 19:08:45",
"pivot": {
"sender_id": 1,
"recipient_id": 3,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 22:56:40",
"status": 1
}
},
{
"id": 2,
"name": "ejoebstl",
"created_at": "2016-06-18 19:08:41",
"updated_at": "2016-06-18 19:08:41",
"pivot": {
"recipient_id": 1,
"sender_id": 2,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 19:53:27",
"status": 0
}
}]
, (*35)
Relationships
, (*36)
Has Relationship With
$user->hasRelationshipWith($person, $status);
$user
must be instance of User
$person
must be instance of User
, User
array or integer (User id)
$status
must be array of integers (Status
), (*37)
, (*38)
Get Relationship With
$user->getRelationshipWith($person, $status);
$user
must be instance of User
$person
must be instance of User
, User
array or integer (User id)
$status
must be array of integers (Status
), (*39)
, (*40)
Has Pending Request From
$user->hasPendingRequestFrom($person);
$user
must be instance of User
$person
must be instance of User
, User
array or integer (User id), (*41)
, (*42)
Query Users Including Relationships
$users = \App\User::whereIn('id', [2,3,4])
->includeRelationshipsWith(1)
->get();
$users
:, (*43)
[{
"id": 2,
"name": "ejoebstl",
"created_at": "2016-06-18 19:08:41",
"updated_at": "2016-06-18 19:08:41",
"friends_i_am_sender": [{
"id": 1,
"name": "arubacao",
"created_at": "2016-06-18 19:08:35",
"updated_at": "2016-06-18 19:08:35",
"pivot": {
"sender_id": 2,
"recipient_id": 1,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 19:53:27",
"status": 0
}
}],
"friends_i_am_recipient": []
},
{
"id": 3,
"name": "harri121",
"created_at": "2016-06-18 19:08:45",
"updated_at": "2016-06-18 19:08:45",
"friends_i_am_sender": [],
"friends_i_am_recipient": [{
"id": 1,
"name": "arubacao",
"created_at": "2016-06-18 19:08:35",
"updated_at": "2016-06-18 19:08:35",
"pivot": {
"recipient_id": 3,
"sender_id": 1,
"created_at": "2016-06-19 19:53:27",
"updated_at": "2016-06-19 22:56:40",
"status": 1
}
}]
},
{
"id": 4,
"name": "random_user",
"created_at": "2016-06-19 19:55:25",
"updated_at": "2016-06-19 19:55:25",
"friends_i_am_sender": [],
"friends_i_am_recipient": []
}]
, (*44)
License
Friends is free software distributed under the terms of the MIT license., (*45)
, (*46)