Download the PHP package amranibrahem/laravel-middleware-generator without Composer
On this page you can find all versions of the php package amranibrahem/laravel-middleware-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amranibrahem/laravel-middleware-generator
More information about amranibrahem/laravel-middleware-generator
Files in amranibrahem/laravel-middleware-generator
Package laravel-middleware-generator
Short Description Auto generate Laravel middleware with role-based authentication
License MIT
Informations about the package laravel-middleware-generator
Laravel Middleware Generator
๐ Generate Custom Middleware Automatically with Professional Code Structure
A powerful Laravel package that automatically generates custom middleware with various authentication types, professional PHPDoc, and complete setup.
โจ Features
- โ Multiple Middleware Types (Role, Permission, Subscription, IP, Header, Custom)
- โ Professional PHPDoc with parameter documentation
- โ Automatic Kernel Registration in Laravel
- โ Auth Configuration Updates for role-based guards
- โ Route Examples with usage patterns
- โ Test File Generation with PHPUnit
- โ Interactive Configuration with beautiful console UI
- โ Custom Error Messages with smart defaults
- โ Boolean Field Support for role checks
- โ Multi-Guard Support (web, api, custom)
๐ Installation
You can install the package via Composer:
The package will automatically register its service provider.
๐ Usage
Basic Commands Generate Role-Based Middleware
Generate with Specific Role
Generate Permission-Based Middleware
Generate with API Guard
Generate with Tests
Advanced Examples IP Whitelist Middleware
Header-Based Authentication
Subscription-Based Access
Boolean Field Check
Custom Error Message
๐ฏ Generated Code Examples
Role-Based Middleware
Permission-Based Middleware
IP-Based Middleware
โ๏ธ Command Options
| Option | Description | Default |
|---|---|---|
--type |
Middleware type | role |
--role |
Role to check | name lowercase |
--permission |
Permission to check | access.{name} |
--subscription |
Subscription plan | premium |
--ip |
Allowed IPs | 127.0.0.1,192.168.1.1 |
--header |
Header to check | X-API-Key |
--header-value |
Header value | your-secret-key |
--message |
Error message | Type-based |
--code |
HTTP status | 403 |
--field |
User field | role |
--boolean |
Boolean field | false |
--model |
User model | User |
--guard |
Auth guard | web |
--test |
Generate test | false |
๐ฃ๏ธ Route Usage Examples
Static Role Check
Dynamic Role Check ` Permission-Based Routes
IP-Based Routes
๐งช Generated Test Example
๐จ Console Output
๐ง Supported Middleware Types
1. Role-Based
- Checks user role against specified value
- Supports dynamic role parameters
- Boolean field support
2. Permission-Based
- Uses Laravel's authorization system
- Supports dynamic permission parameters
- Works with gates and policies
3. Subscription-Based
- Checks user subscription plans
- Perfect for SaaS applications
- Customizable field names
4. IP-Based
- IP address whitelisting
- Multiple IP support
- Internal API protection
5. Header-Based
- API key authentication
- Custom header validation
- Secret key verification
6. Custom
- Extensible template
- Manual implementation
- Custom business logic
๐ก๏ธ Security Features
- Proper Authentication Checks - Verifies user existence before role checks
- HTTP Status Codes - Appropriate status codes (401, 403, 503)
- JSON Responses - Consistent error response format
- Input Validation - Safe parameter handling
- Guard Support - Multiple authentication guards
๐ Auto-Generated Files
- Middleware File -
app/Http/Middleware/{Name}Middleware.php - Kernel Registration - Auto-added to
app/Http/Kernel.php - Auth Configuration - Updated
config/auth.phpfor roles - Route Examples - Added to
routes/api.phporroutes/web.php - Test Files - Generated in
tests/Unit/Middleware/
๐ก Best Practices
Use Boolean Fields for Single Roles
Custom HTTP Status Codes
API-Focused Middleware
Internal API Protection
๐ Troubleshooting
Middleware not found in routes?
- Run
php artisan route:listto see registered middleware - Check
Kernel.phpfor proper registration
Authentication not working?
- Verify guard configuration in
config/auth.php - Check user model field names match middleware configuration
Tests failing?
- Implement actual test logic in generated test files
- Mock user authentication in tests
๐ Comparison with Alternatives
| Feature | This Package | Manual Creation |
|---|---|---|
| Time Saving | โ (Seconds) | โ (Minutes/Hours) |
| Professional Structure | โ | โ |
| Auto Registration | โ | โ |
| Route Examples | โ | โ |
| Test Generation | โ | โ |
| Multiple Types | โ | โ |
| Interactive Setup | โ | โ |
| Error Handling | โ | โ |
๐ License
This package is open-sourced software licensed under the MIT license.
๐ค Contributing
Please see CONTRIBUTING for details.
๐ Reporting Issues
If you discover any issues, please use the GitHub issue tracker.
๐ Credits
๐ Links
โญ Star us on GitHub if this package helped you!
๐ Happy coding!