PHPackages                             cjmellor/blockade - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. cjmellor/blockade

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

cjmellor/blockade
=================

Allow a User Model to block another User Model

v1.2.0(2y ago)2014[1 PRs](https://github.com/cjmellor/blockade/pulls)MITPHPPHP ^8.2|^8.3CI passing

Since Mar 17Pushed 1w ago1 watchersCompare

[ Source](https://github.com/cjmellor/blockade)[ Packagist](https://packagist.org/packages/cjmellor/blockade)[ Docs](https://github.com/cjmellor/blockade)[ RSS](/packages/cjmellor-blockade/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (5)Dependencies (7)Versions (8)Used By (0)

Allow a User Model to Block Another User Model
==============================================

[](#allow-a-user-model-to-block-another-user-model)

[![Packagist Version](https://camo.githubusercontent.com/cc289d44a0784f726b2750871ea498e86518cb7a272930126de4e6b54558d028/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636a6d656c6c6f722f626c6f636b6164653f636f6c6f723d7267622532383536253230313839253230323438253239266c6162656c3d72656c65617365267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/cc289d44a0784f726b2750871ea498e86518cb7a272930126de4e6b54558d028/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636a6d656c6c6f722f626c6f636b6164653f636f6c6f723d7267622532383536253230313839253230323438253239266c6162656c3d72656c65617365267374796c653d666f722d7468652d6261646765)[![GitHub Tests Action Status](https://camo.githubusercontent.com/c74d6d2dcbae32e462f33f311b684816d262069f0e5b65d2db019f055c77a26e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636a6d656c6c6f722f626c6f636b6164652f72756e2d706573742e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666f722d7468652d626164676526636f6c6f723d726762253238313334253230323339253230313238253239)](https://github.com/cjmellor/blockade/actions?query=workflow%3Arun-tests+branch%3Amain)[![Packagist Downloads](https://camo.githubusercontent.com/92ad01ce18325ed09a1529805fc7f92a61e0b04a42ccd179d21c5aa8485f6885/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636a6d656c6c6f722f626c6f636b6164653f636f6c6f723d7267622532383234392532303131352532303232253239267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/92ad01ce18325ed09a1529805fc7f92a61e0b04a42ccd179d21c5aa8485f6885/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636a6d656c6c6f722f626c6f636b6164653f636f6c6f723d7267622532383234392532303131352532303232253239267374796c653d666f722d7468652d6261646765)[![Packagist PHP Version](https://camo.githubusercontent.com/289c78355610ecabe29aa537cfc52cde1a488cc5d4b985359c206224b1958281/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f636a6d656c6c6f722f626c6f636b6164652f7068703f636f6c6f723d726762253238313635253230313830253230323532253239266c6f676f3d706870266c6f676f436f6c6f723d726762253238313635253230313830253230323532253239267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/289c78355610ecabe29aa537cfc52cde1a488cc5d4b985359c206224b1958281/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f636a6d656c6c6f722f626c6f636b6164652f7068703f636f6c6f723d726762253238313635253230313830253230323532253239266c6f676f3d706870266c6f676f436f6c6f723d726762253238313635253230313830253230323532253239267374796c653d666f722d7468652d6261646765)[![Laravel Version](https://camo.githubusercontent.com/74ff7fca259d5de1178d0c71d4370c2548ee770a332fd1dbaac4ce7a7d769141/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531302e302d7267622832333525323036382532303530293f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://camo.githubusercontent.com/74ff7fca259d5de1178d0c71d4370c2548ee770a332fd1dbaac4ce7a7d769141/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d25354531302e302d7267622832333525323036382532303530293f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)

Allow a User to block another User. Blocking a User will prevent the blocker from seeing the blockees data.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require cjmellor/blockade
```

You can publish and run the migrations with:

```
php artisan vendor:publish --tag="blockade-migrations"

php artisan migrate
```

and publish the config file with:

```
php artisan vendor:publish --tag="blockade-config"
```

This is the contents of the published config file:

```
return [
    /**
     * If your User model different to the default, you can specify it here.
     */
    'user_model' => 'App\Models\User',

    /**
     * Specify the user model's foreign key.
     */
    'user_foreign_key' => 'user_id',

    /**
     * Specify the table name for the blocks table.
     */
    'blocks_table' => 'blocks',

    /**
     * Specify the foreign key for the blocker.
     */
    'blocker_foreign_key' => 'blocker_id',

    /**
     * Specify the foreign key for the blocked.
     */
    'blocked_foreign_key' => 'blocked_id',

    /**
     * Schedule the cleanup of expired blocks.
     */
    'schedule_cleanup' => false,
];
```

Usage
-----

[](#usage)

### Using the Traits

[](#using-the-traits)

#### CanBlock

[](#canblock)

Add the `CanBlock` trait to your User model.

This trait should only ever be added to your User model.

```
use Cjmellor\Blockade\Concerns\CanBlock;

class User
{
    use CanBlock;

    // ...
}
```

#### HasBlocked

[](#hasblocked)

Use this trait in your Models where you would not want a User to see the Model of a User they have blocked.

> Example: you have a `Comment` Model and User 7 has blocked User 8 so User 7 should not be able to see any comments made by User 8.

```
use Cjmellor\Blockade\Concerns\HasBlocked;

class Comment
{
    use HasBlocked;

    // ...
}
```

### Block a User

[](#block-a-user)

A User can block another User by supplying a User model, or just the ID of the User to be blocked.

```
$user->block(User::find(2)));

// or

$user->block(2);
```

> **Note:**You cannot block yourself.

### Unblock a User

[](#unblock-a-user)

A User can unblock another User by supplying a User model, or just the ID of the User to be unblocked.

```
$user->unblock(User::find(2)));

// or

$user->unblock(2);
```

### Checking if a User is blocked

[](#checking-if-a-user-is-blocked)

You can run a check to see if you're already blocking a User or not.

```
$user->isBlocking(User::find(2)));

// or

$user->isBlocking(2);
```

### Set a block expiry

[](#set-a-block-expiry)

You can set an expiry date when blocking a User. This will automatically unblock the User after the expiry date has passed.

```
$user->block(User::find(2), expiresAt: now()->addDays(7)));
```

This example will block the User for 7 days. After 7 days, the User will be unblocked.

#### ⏱️ Scheduling the cleanup of expired blocks

[](#️-scheduling-the-cleanup-of-expired-blocks)

By default, a blocked User with an expiry will not be removed after the expiry time as past.

If you want to automatically remove expired blocks, you can set the `schedule_cleanup` config value in the `config/blockade` config file to `true`.

If you want more control over when the cleanup is run, there is an artisan command that can be run to remove expired blocks.

```
php artisan unblock:expired
```

You can also schedule this command to run automatically.

```
$schedule->command('unblock:expired')->everyMinute();
```

> **Note**
>
> Don't forget to add the command to the `App\Console\Kernel` `schedule()` method.

### Events

[](#events)

When a User is blocked, a `UserBlocked` event is fired.

When a User is unblocked, a `UserUnblocked` event is fired.

The `User` Model of the blocked or unblocked User is passed to the event so you can listen for these events and perform further actions.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance64

Regular maintenance activity

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 54.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~93 days

Total

5

Last Release

831d ago

PHP version history (2 changes)v1.0.0PHP ^8.1

v1.2.0PHP ^8.2|^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/801039?v=4)[cmellor](/maintainers/cmellor)[@cmellor](https://github.com/cmellor)

---

Top Contributors

[![cjmellor](https://avatars.githubusercontent.com/u/1848476?v=4)](https://github.com/cjmellor "cjmellor (47 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (25 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (14 commits)")

---

Tags

laravelcjmellorblockade

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/cjmellor-blockade/health.svg)

```
[![Health](https://phpackages.com/badges/cjmellor-blockade/health.svg)](https://phpackages.com/packages/cjmellor-blockade)
```

###  Alternatives

[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[hasinhayder/tyro

Tyro - The ultimate Authentication, Authorization, and Role &amp; Privilege Management solution for Laravel 12 &amp; 13

6804.7k6](/packages/hasinhayder-tyro)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[masterix21/laravel-licensing

Laravel licensing package with polymorphic assignment to any model, activation keys, expirations/renewals, and seat control via LicenseUsage. Supports offline verification with public-key–signed tokens, a CLI to generate/rotate/revoke keys, and an extensible architecture via config and contracts.

1563.1k4](/packages/masterix21-laravel-licensing)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
