Download the PHP package gecche/laravel-bannable without Composer
On this page you can find all versions of the php package gecche/laravel-bannable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-bannable
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 |
---|---|
5.5.x | 1.1.x |
5.6.x | 1.2.x |
5.7.x | 1.3.x |
5.8.x | 1.4.x |
6.x | 2.x |
7.x | 3.x |
8.x | 4.x |
9.x | 5.x |
10.x | 10.x |
11.x | 11.x |
Installation
Add gecche/laravel-bannable as a requirement to composer.json:
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:
Then, if you use Eloquent users you have to add the bannable features to the User model class:
Finally, you have to change the auth.php
configuration, changing the user provider's driver to eloquent-bannable
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:
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.