ghanem/friendship

friendship system for Laravel 5

1.0 2015-10-23 17:31 UTC

This package is auto-updated.

Last update: 2024-11-16 22:48:07 UTC


README

This package will allow you to add a full report system into your Laravel application.

Installation

First, pull in the package through Composer.

composer require ghanem/friendship

And then include the service provider within app/config/app.php.

'providers' => [
    Ghanem\Friendship\FriendshipServiceProvider::class
];

At last you need to publish

php artisan vendor:publish --provider="Ghanem\Friendship\FriendshipServiceProvider" 

and run the migration.

php artisan migrate

Setup a Model

<?php

namespace App;

use Ghanem\Friendship\Contracts\Friendable;
use Ghanem\Friendship\Traits\Friendable as FriendableTrait;
use Illuminate\Database\Eloquent\Model;

class User extends Model implements Friendable
{
    use FriendableTrait;
}

Examples

Send a Friend-Request to a Model

$user->befriend($userToBeFriendsWith);

Unfriend a Model

$user->unfriend($userToBeFriendsWith);

Deny a Friend-Request from a Model

$user->denyFriendRequest($userToBeFriendsWith);

Accept a Friend-Request from a Model

$user->acceptFriendRequest($userToBeFriendsWith);

Block a Model

$user->blockFriendRequest($userToBeFriendsWith);

Unblock a Model

$user->unblockFriendRequest($userToBeFriendsWith);

Check if the Model has blocked another Model

$user->hasBlocked($userToBeFriendsWith);

Check if one Model is blocked by another Model

$user->isBlockedBy($userToBeFriendsWith);

Check if a Friendship exists between two models

$user->isFriendsWith($userToBeFriendsWith);

Get a single friendship

$user->getFriendship($userToBeFriendsWith);

Get a list of all Friendships

$user->getAllFriendships();

Get a list of pending Friendships

$user->getPendingFriendships();

Get a list of accepted Friendships

$user->getAcceptedFriendships();

Get a list of denied Friendships

$user->getDeniedFriendships();

Get a list of blocked Friendships

$user->getBlockedFriendships();

Get a list of pending Friend-Requests

$user->getFriendRequests();