Skip to content
This repository was archived by the owner on Nov 4, 2020. It is now read-only.

hareku/laravel-user-blockable

Folders and files

NameName
Last commit message
Last commit date

Latest commit

May 30, 2017
26fd3bc · May 30, 2017

History

1 Commit
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017
May 30, 2017

Repository files navigation

Laravel 5 User Block System

This package helps you to add user block system to your project.

  • So simply and easy.
  • Use "ON DELETE CASCADE" in block relationships table.

Caution

  • Support Laravel 5.4~
  • Required php >=7.0

Installation

First, pull in the package through Composer.

Run composer require hareku/laravel-user-blockable

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

'providers' => [
    Hareku\LaravelBlockable\BlockableServiceProvider::class,
];

Publish the config file. (blockable.php)

$ php artisan vendor:publish --provider="Hareku\LaravelBlockable\BlockableServiceProvider"

Finally, use Blockable trait in User model.

use Hareku\LaravelBlockable\Traits\Blockable;

class User extends Model
{
    use Blockable;
}

Usage

Block a user or users

$user->block(1);
$user->block([1,2,3,4]);

Add blockers

$user->addBlockers(1);
$user->addBlockers([1,2,3,4]);

Unblock a user or users

$user->unblock(1);
$user->unblock([1,2,3,4]);

Get blocker users / blocked by users

// blocker users
$user->blockerUsers()->get(); // Get blocker user models.
$user->blockerRelationships()->get(); // Get blocker relationship models.

// blocked by users
$user->blockingUsers()->get();
$user->blockingRelationships()->get();

Check if it is blocking

$user->isBlocking(1);
$user->isBlocking([1,2,3,4]);

Check if it is being blocked

$user->isBlockedBy(1);
$user->isBlockedBy([1,2,3,4]);

Check if it is mutual block

$user->isMutualBlock(1);
$user->isMutualBlock([1,2,3,4]);

Get blocker/blocked IDs

$user->block([1,2,3]);

$user->blockerIds(); // [1,2,3]
$user->blockingIds();

Reject user ids

$user->blockerUsers()->pluck('id')->all(); // [1,2,3]
$user->rejectNotBlocker([1,2,3,4,5]); // [1,2,3]
$user->block([1,2,3]);
$user->rejectNotBlocking([1,2,3,4,5]); // [1,2,3]

License

MIT

Author

hareku ([email protected])

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages