arubacao / friends
Manage Friends in Laravel
Installs: 1 142
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 2
Forks: 5
Open Issues: 1
Requires
- php: >=5.6.0
- illuminate/database: ^5.2
- illuminate/support: ^5.2
Requires (Dev)
- graham-campbell/testbench: ^3.0
- mockery/mockery: dev-master
- phpunit/phpunit: ^4.1
This package is auto-updated.
Last update: 2021-05-09 22:10:29 UTC
README
This package is unmaintained and was only a quick hacking around. Don't use in production code.
Friends (Laravel 5 Package)
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
- 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
For Laravel 5.*
Pull in Package with Composer
composer require arubacao/friends
Register Service Provider
Include the service provider inside config/app.php
.
'providers' => [ ... Arubacao\Friends\FriendsServiceProvider::class, ... ];
Run Migrations
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.
Prepare User Model
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.
## ConfigurationConfiguration File friends.php
(Optional)
Find 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
[{ "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 } }]#### 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
[{ "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 } }]#### Retrieve Any Friends **Remember:** > Just like in the real life a 'friend' or 'friendship' can be anything, also negative ;) Get all users who have any kind of friendship/relationship with
$user
$friends = $user->any_friends();
$user
must be instance of User
[{ "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 } }]### Relationships #### Has Relationship With ```php $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`) #### Get Relationship With ```php $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`) #### Has Pending Request From ```php $user->hasPendingRequestFrom($person); ``` `$user` must be instance of `User` `$person` must be instance of `User`, `User` array or integer (User id) ### Query Users Including Relationships
$users = \App\User::whereIn('id', [2,3,4]) ->includeRelationshipsWith(1) ->get();
[{ "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": [] }]## License
Friends is free software distributed under the terms of the MIT license.