gecche/laravel-bannable

A simple package to handle bannable users
1,010 4
Install
composer require gecche/laravel-bannable
Latest Version:v13.0
Laravel:13
License:MIT
Last Updated:Mar 30, 2026
Links: GitHub  ·  Packagist
Maintainer: gecche

License Laravel Laravel Laravel Laravel Laravel Laravel Laravel Laravel Laravel

laravel-bannable

Laravel package to handle bannable users

Description

In many apps, your users could be banned from the platform due to various causes, i.e.: for not respecting platform's rules or for not respecting other users or simply for not paying the monthly fees :)

This package adds a banned attribute to the standard users in order to prevent the authentication of such banned users. Fully tested.

Documentation

Version Compatibility

Laravel Bannable
13.x 13.x
12.x 12.x
11.x 11.x
10.x 10.x
9.x 5.x
8.x 4.x
7.x 3.x
6.x 2.x
5.8.x 1.4.x
5.7.x 1.3.x
5.6.x 1.2.x
5.5.x 1.1.x

Installation

Add gecche/laravel-bannable as a requirement to composer.json:

{
    "require": {
        "gecche/laravel-bannable": "13.*"
    }
}

This package makes use of the discovery feature.

Basic usage

To use the package's features, first you have to publish and to run the provided migration which simply adds a banned boolean field to the users' table.

Then, if you use Eloquent users you have to add the bannable features to the User model class:

php artisan vendor:publish --provider="Gecche\Bannable\BannableServiceProvider"

Then, if you use Eloquent users you have to add the bannable features to the User model class:

<?php

namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Gecche\Bannable\Bannable;
use Gecche\Bannable\Contracts\Bannable as BannableContract;

class User extends Authenticatable implements BannableContract
{
    use Notifiable;
    use Bannable;

...

Finally, you have to change the auth.php configuration, changing the user provider's driver to eloquent-bannable

'providers' => [
        'users' => [
            'driver' => 'eloquent-bannable',
            'model' => App\User::class,
        ],
    ],

That's it! From now on, if an user has the banned attribute set to true, it will not be able to authenticate to the platform.

The package provides a database-bannable user provider's driver too.

Change the name of the "banned" attribute

To change the name of the "banned" attribute, simply override in you Eloquent User class the getBannedName method, replacing the banned name with whatever name you want:

    /**
     * Get the column name for the "banned" value.
     *
     * @return string
     */
    public function getBannedName()
    {
        return 'banned';
    }

Remember to change the name of the database field too!

Ban and Unban users

The Gecche\Bannable\Bannable trait also provides two simple methods, namely ban and unban which obviously ban and unban the user. Both methods also fire a correspondent event, namely Gecche\Bannable\Events\Banned and Gecche\Bannable\Events\Unbanned events.

Related Packages

lab404/laravel-impersonate

Laravel Impersonate is a plugin that allows to you to authenticate as your users...

21,629,143 2,343
sarav/laravel-multiauth

A Simple Laravel Package for handling multiple authentication

31,350 50
yajra/laravel-acl

Laravel ACL is a simple role, permission ACL for Laravel Framework.

135,809 113
lab404/laravel-auth-checker

Laravel Auth Checker allows you to log users authentication, devices authenticat...

169,111 222
spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or applicatio...

65,490,992 5,908

Version History

Version Released Laravel License
v13.0 ^13.0 MIT
v12.0 ^12.0 MIT
v11.0 ^11.0 MIT
v10.0 ^10.0 MIT
v5.1 ^9.0 MIT