PHPackages                             notchafrica/ban - 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. [Database &amp; ORM](/categories/database)
4. /
5. notchafrica/ban

ActiveLibrary[Database &amp; ORM](/categories/database)

notchafrica/ban
===============

Laravel Ban simplify blocking and banning Eloquent models.

1.0(2y ago)06MITPHPPHP ^8.0

Since Sep 21Pushed 2y agoCompare

[ Source](https://github.com/notchafrica/ban)[ Packagist](https://packagist.org/packages/notchafrica/ban)[ Docs](https://komarev.com/sources/laravel-ban)[ RSS](/packages/notchafrica-ban/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

Laravel Ban
===========

[](#laravel-ban)

[![cog-laravel-ban](https://user-images.githubusercontent.com/1849174/44558308-1d8e0580-a74c-11e8-8e2a-ec297bbc3f12.png)](https://user-images.githubusercontent.com/1849174/44558308-1d8e0580-a74c-11e8-8e2a-ec297bbc3f12.png)

[![Discord](https://camo.githubusercontent.com/86e83e2f2ffe2f5caffed9d8886bb512bf42bf927dd8bb8e864d9e9983313ff7/68747470733a2f2f696d672e736869656c64732e696f2f7374617469632f76313f6c6f676f3d646973636f7264266c6162656c3d266d6573736167653d446973636f726426636f6c6f723d333633393366267374796c653d666c61742d737175617265)](https://discord.gg/nAZBEkH)[![Releases](https://camo.githubusercontent.com/584b2d1b1ed229fce98bcd09c1491b718303c754728160fc862fd509eb3690fb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6379626572636f672f6c61726176656c2d62616e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/cybercog/laravel-ban/releases)[![Build Status](https://camo.githubusercontent.com/8e00aaab2cf5422a12aa8845cf3eeea9f403aa3f702a1b89cd471b9538342336/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6379626572636f672f6c61726176656c2d62616e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/cybercog/laravel-ban)[![StyleCI](https://camo.githubusercontent.com/8fd123ab0529452a37edc4a9e02088f7fa5d3bffc58c4b854ec9d3fc335a07da/68747470733a2f2f7374796c6563692e696f2f7265706f732f38333937313035352f736869656c64)](https://styleci.io/repos/83971055)[![Code Quality](https://camo.githubusercontent.com/c742e10683d20ef2940cc247464c1939e1f0f0e002a5445118d7223ed189ba71/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6379626572636f672f6c61726176656c2d62616e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/cybercog/laravel-ban/?branch=master)[![License](https://camo.githubusercontent.com/802e74443d9a85d2af4ca48954f3c62400ee674b29054a29e7160fcc12525018/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6379626572636f672f6c61726176656c2d62616e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/cybercog/laravel-ban/blob/master/LICENSE)

Introduction
------------

[](#introduction)

Laravel Ban simplify management of Eloquent model's ban. Make any model bannable in a minutes!

Use case is not limited to User model, any Eloquent model could be banned: Organizations, Teams, Groups and others.

Contents
--------

[](#contents)

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
    - [Prepare bannable model](#prepare-bannable-model)
    - [Prepare bannable model database table](#prepare-bannable-model-database-table)
    - [Available methods](#available-methods)
    - [Scopes](#scopes)
    - [Events](#events)
    - [Middleware](#middleware)
    - [Scheduling](#scheduling)
- [Integrations](#integrations)
- [Changelog](#changelog)
- [Upgrading](#upgrading)
- [Contributing](#contributing)
- [Testing](#testing)
- [Security](#security)
- [Contributors](#contributors)
- [Alternatives](#alternatives)
- [License](#license)
- [About CyberCog](#about-cybercog)

Features
--------

[](#features)

- Model can have many bans.
- Removed bans kept in history as soft deleted records.
- Most parts of the logic is handled by the `BanService`.
- Has middleware to prevent banned user route access.
- Use case is not limited to `User` model, any Eloquent model could be banned.
- Events firing on models `ban` and `unban`.
- Designed to work with Laravel Eloquent models.
- Has [Laravel Nova support](https://github.com/cybercog/laravel-nova-ban).
- Using contracts to keep high customization capabilities.
- Using traits to get functionality out of the box.
- Following PHP Standard Recommendations:
    - [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
    - [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
    - [PSR-4 (Autoloading Standard)](http://www.php-fig.org/psr/psr-4/).
- Covered with unit tests.

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

[](#installation)

First, pull in the package through Composer:

```
composer require cybercog/laravel-ban
```

#### Registering package

[](#registering-package)

> The package will automatically register itself. This step required for Laravel 5.4 or earlier releases only.

Include the service provider within `app/config/app.php`:

```
'providers' => [
    Cog\Laravel\Ban\Providers\BanServiceProvider::class,
],
```

#### Apply database migrations

[](#apply-database-migrations)

At last you need to publish and run database migrations:

```
php artisan vendor:publish --provider="Cog\Laravel\Ban\Providers\BanServiceProvider" --tag="migrations"
php artisan migrate
```

Usage
-----

[](#usage)

### Prepare bannable model

[](#prepare-bannable-model)

```
use Cog\Contracts\Ban\Bannable as BannableInterface;
use Cog\Laravel\Ban\Traits\Bannable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements BannableInterface
{
    use Bannable;
}
```

### Prepare bannable model database table

[](#prepare-bannable-model-database-table)

Bannable model must have `nullable timestamp` column named `banned_at`. This value used as flag and simplify checks if user was banned. If you are trying to make default Laravel User model to be bannable you can use example below.

#### Create a new migration file

[](#create-a-new-migration-file)

```
php artisan make:migration add_banned_at_column_to_users_table
```

Then insert the following code into migration file:

```
