Laravel Ban is a package that simplifies blocking and banning Eloquent models. Using this package, you can make a model "bannable" in minutes.
The use case for this package goes beyond a
User model; you can add the concept of a ban to any Eloquent model. The main features of this package include:
- 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.
- Using contracts to keep high customization capabilities.
- Using traits to get functionality out of the box.
The package has a nice API that makes banning the model simple:
1$user->ban();23$user->ban([4 'comment' => 'Enjoy your ban!',5]);67// A ban that has a ban expiry date8$user->ban([9 'expired_at' => '+1 month',10]);1112// Remove a ban13$user->unban();1415// Boolean checks16$user->isBanned();17$user->isNotBanned();18$ban->isTemporary();
The package also provides nice conveniences like middleware, events, scopes, and auto-applying scopes to a model.
You can learn more about this package, get full installation instructions, and view the source code on GitHub.