Download the PHP package mchev/banhammer without Composer
On this page you can find all versions of the php package mchev/banhammer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mchev/banhammer
More information about mchev/banhammer
Files in mchev/banhammer
Package banhammer
Short Description Banhammer for Laravel allows you to ban any Model by key and by IP.
License MIT
Homepage https://github.com/mchev/banhammer
Informations about the package banhammer
Banhammer 🔨
A simple and powerful ban package for Laravel - ban models, IPs, and countries with ease.
Banhammer allows you to ban any Eloquent model, IP addresses, and even entire countries. Bans can be permanent or temporary with automatic expiration.
📋 Table of Contents
- Quick Start
- Features
- Installation
- Usage Guide
- Banning Models
- Banning IPs
- Country Blocking
- Middleware
- Scheduler
- Events
- Advanced Topics
- Metas
- UUIDs
- Upgrading
- Development
🚀 Quick Start
Add the trait to your model:
Ban a user:
✨ Features
- ✅ Ban any Eloquent model (User, Team, etc.)
- ✅ Ban IP addresses (single or multiple)
- ✅ Block entire countries
- ✅ Temporary or permanent bans
- ✅ Automatic expiration handling
- ✅ Middleware protection
- ✅ Event system
- ✅ Metadata support
📦 Installation
Requirements
- PHP 8.0+
Laravel compatibility
| Laravel | Supported since Banhammer |
|---|---|
| 9.x | v1.0.0 |
| 10.x | v1.0.0 |
| 11.x | v2.2.0 |
| 12.x | v2.4.0 |
| 13.x | v2.5.0 |
Setup
-
Install the package:
-
Publish and run migrations:
-
Publish config (optional):
💡 The config file allows you to customize table name, model, fallback URLs, and more.
📖 Usage Guide
Banning Models
Make a Model Bannable
Add the Bannable trait to any model:
💡 You can add the trait to multiple models (User, Team, Group, etc.)
Basic Operations
| Action | Code |
|---|---|
| Ban a user | $user->ban() |
| Ban with expiration | $user->banUntil('2 days') |
| Check if banned | $user->isBanned() |
| Check if not banned | $user->isNotBanned() |
| Unban | $user->unban() |
Advanced Ban Options
⚠️ Without
expired_at, the ban is permanent.
Query Scopes
List Bans
Banning IPs
Basic Operations
Unban IPs
Check & List Banned IPs
Country Blocking
Block access from specific countries automatically.
Configuration
-
Enable country blocking in
config/ban.php: - Specify blocked countries:
That's it! The middleware will automatically block requests from these countries.
⚠️ Rate Limit Notice: The free version of ip-api.com has a limit of 45 requests/minute. Exceeding this will result in 429 errors until the limit resets.
💡 Want to improve this? If you have suggestions for better geolocation services or want to contribute improvements, please open an issue or submit a pull request.
Middleware
Protect your routes with ban middleware:
Available Middleware
| Middleware | Description |
|---|---|
auth.banned |
Blocks banned users |
ip.banned |
Blocks banned IPs |
logout.banned |
Logs out and blocks banned users/IPs |
Usage
💡 Tip:
logout.bannedincludes the functionality of bothauth.bannedandip.banned, so you don't need to use them together.
Scheduler
Banhammer automatically deletes expired bans using Laravel's scheduler.
Setup
⚠️ Important: You must have a cron job running Laravel's scheduler:
Configuration
By default, the banhammer:unban command runs every minute. You can customize this:
Disable automatic scheduler:
Or via environment:
Change frequency:
Or via environment:
Available frequencies: everyMinute, everyFiveMinutes, everyTenMinutes, everyFifteenMinutes, everyThirtyMinutes, hourly, daily, twiceDaily, etc.
Events
Listen to ban/unban events:
🔧 Advanced Topics
Metas
Store additional data with bans:
Filter by Meta
Ban with Metas
UUIDs
To use UUIDs instead of auto-incrementing IDs:
-
Publish migrations:
-
Edit the migration:
-
Create a custom Ban model:
- Update config:
Upgrading To 2.0 from 1.x
-
Update composer.json:
-
Update the package:
- Update configuration:
🛠️ Development
Commands
Programmatic Usage
Testing
🤝 Contributing
We welcome contributions! Please:
- Open issues for bug reports or feature requests
- Submit pull requests (mark as "ready for review")
- Ensure all tests pass
- Follow Laravel coding standards
💡 Pull requests in "draft" state will be closed after a few days of inactivity.
🙏 Credits
Inspired by laravel-ban from cybercog.
📄 License
The MIT License (MIT). Please see License File for more information.
All versions of banhammer with dependencies
illuminate/cache Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/routing Version ^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^9.0|^10.0|^11.0|^12.0|^13.0