This package is unmaintained and was only a quick hacking around. Don't use in production code.
- Send Friend Requests
- Accept Friend Requests
- Deny Friend Requests
- Delete Friends
- Installation
- Configuration
- Usage
- Friend Requests
- Send Friend Request
- Accept Friend Request
- Deny Friend Request - My Friends
- Is Friend With
- Delete Friend
- Retrieve Friends
- Retrieve Incoming Friends
- Retrieve Any Friends - Relationships
- Has Relationship With
- Get Relationship With
- Has Pending Request From - Query Users Including Relationships
- Friend Requests
- License
composer require arubacao/friends
Include the service provider inside config/app.php
.
'providers' => [
...
Arubacao\Friends\FriendsServiceProvider::class,
...
];
Publish the migration and migrate the database
php artisan vendor:publish --provider="Arubacao\Friends\FriendsServiceProvider"
php artisan migrate
After the migration, 1 new table will be created:
friends
— stores relationships/friendships between Users
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.
Include Friendable
Trait in User
Model
use Arubacao\Friends\Traits\Friendable;
class User extends Model
{
use Friendable; // Add this trait to your model
...
}
And you are ready to go.
## ConfigurationFind friends.php
in your config folder. Make sure you published the package beforehand.
user_model
— This is the applicationsUser
model used by Friends.users_table
— This is the applicationsusers
table name used by Friends.
$friends = $user->friends();
$user
must be instance of User
$friends
:
[{
"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
}
}]
$friends = $user->incoming_friends();
$user
must be instance of User
$friends
:
[{
"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
}
}]
- Get all users who have any kind of friendship/relationship with
$user
$friends = $user->any_friends();
$user
must be instance of User
$friends
:
[{
"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
}
}]
$users = \App\User::whereIn('id', [2,3,4])
->includeRelationshipsWith(1)
->get();
$users
:
[{
"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": []
}]
Friends is free software distributed under the terms of the MIT license.