New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

gecche/laravel-bannable

A simple package to handle bannable users
1,123 4
Install
composer require gecche/laravel-bannable
Latest Version:v13.0
Laravel:13
Older releases:5 – 12
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

acacha/user

A boosted User for Laravel

254,177 26
sargilla/user

Clase Usuario para laravel

528 0
haruncpi/laravel-user-activity

Monitor user activity easily!

205,772 426
custom-d/user-security-recovery

A user security recovery

2,691 0
ahuggins/utilities

Artisan commands for user management, password reset, create user

318 1

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