Ban Eloquent Models With the Laravel Ban Package
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:
4 'comment' => 'Enjoy your ban!',
7// A ban that has a ban expiry date
9 'expired_at' => '+1 month',
12// Remove a ban
15// Boolean checks
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.
Credit: Source link