GithubHelp home page GithubHelp logo

laravel-user-blockable's Introduction

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])

laravel-user-blockable's People

Contributors

hareku avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.