Download the PHP package litepie/shield without Composer
On this page you can find all versions of the php package litepie/shield. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download litepie/shield
More information about litepie/shield
Files in litepie/shield
Package shield
Short Description A production-ready Laravel role and permission-based access control system
License MIT
Informations about the package shield
Litepie Shield - Laravel Role and Permission System
A production-ready Laravel package for role and permission-based access control, built from scratch with all the features from Spatie's Laravel Permission package and enhanced with additional capabilities.
โจ Features
- ๐ Roles and Permissions: Comprehensive role-based access control system
- ๐ก๏ธ Multiple Guards: Support for multiple authentication guards (web, api, custom)
- ๐ข Multi-Tenant Ready: Complete tenant/organization isolation with dynamic context switching
- ๐ Wildcard Permissions: Hierarchical permissions with pattern matching (
posts.*
,admin.*
) - โก High Performance Caching: Redis/file-based caching with automatic invalidation
- ๐จ Blade Directives: Beautiful template permission checking (
@role
,@permission
) - ๐ง Middleware Protection: Route-level security with flexible middleware
- ๐ก Event System: Listen to permission/role changes with Laravel events
- ๐ Passport Integration: Full support for API authentication and machine-to-machine tokens
- โ๏ธ Artisan Commands: Complete CLI management for roles, permissions, and users
- ๐ Laravel Octane Ready: Optimized for high-performance Laravel Octane deployments
- ๐ Database Query Scopes: Elegant Eloquent scopes for complex queries
- ๐งช Fully Tested: Comprehensive test suite for production reliability
๐ Table of Contents
- Installation
- Quick Setup
- Configuration
- Basic Usage
- Advanced Features
- Multi-Tenant Support
- Wildcard Permissions
- Middleware
- Blade Directives
- Database Queries
- Events
- API Integration
- Performance & Caching
- Artisan Commands
- Testing
- Migration from Spatie
- Contributing
๐ Installation
Requirements:
- PHP 8.2 or higher
- Laravel 10.x, 11.x, or 12.x
Publish the migration and config file:
Run the migrations:
Quick Setup
Create Super User
After installation, create a super user with full admin privileges:
This command will:
- Create a "Super Admin" role with all permissions
- Create comprehensive permissions for your application
- Create a user account and assign the Super Admin role
- Provide you with login credentials
You can also run it non-interactively:
โ๏ธ Configuration
The configuration file config/shield.php
provides extensive customization options:
Configuration Options Explained
Option | Description | Default |
---|---|---|
models.permission |
Permission model class | Litepie\Shield\Models\Permission |
models.role |
Role model class | Litepie\Shield\Models\Role |
table_names.* |
Database table names | Standard naming |
cache.expiration_time |
Cache duration | 24 hours |
cache.store |
Cache store to use | default |
tenants |
Enable multi-tenant support | false |
use_passport_client_credentials |
API authentication | false |
enable_wildcard_permission |
Hierarchical permissions | false |
events_enabled |
Event firing | false |
๐ Basic Usage
Setting up Models
Add the HasRoles
trait to your User model:
For models that only need permissions (not roles), use HasPermissions
:
Creating Roles and Permissions
Basic Creation
Advanced Creation with Guards
Assigning Roles and Permissions
Role Assignment
Direct Permission Assignment
Checking Permissions and Roles
Permission Checks
Role Checks
Advanced Checks
๐ Advanced Features
Custom Models
Extend the base models to add your own functionality:
Update your config:
Multiple Guards
Shield supports multiple authentication guards seamlessly:
Permission Inheritance
Create hierarchical permission structures:
๐ข Multi-Tenant Support
Shield provides complete multi-tenant isolation with tenant-based permissions.
Enable Tenants
Tenant Context Management
Tenant-Specific Operations
Custom Tenant Resolver
Implement automatic tenant detection:
Register in AppServiceProvider
:
Multi-Tenant Middleware
โญ Wildcard Permissions
Register the middleware in your Kernel.php
:
Advanced Middleware Usage
Custom Middleware
Create your own permission middleware:
๐จ Blade Directives
Beautiful template-level permission checking.
Role Directives
Permission Directives
Advanced Blade Usage
๐๏ธ Database Queries
Powerful Eloquent scopes for complex permission queries.
User Queries
Tenants Feature
Enable tenants in config:
Set the tenant context:
Create hierarchical permissions with pattern matching:
Enable Wildcards
Wildcard Patterns
Wildcard Examples
๐ง Middleware
Protect your routes with flexible middleware options.
Register Middleware
Add to app/Http/Kernel.php
:
Basic Usage
bash
Create permission
php artisan shield:create-permission "edit articles" php artisan shield:create-permission "manage users" --guard=web
Create role
php artisan shield:create-role writer php artisan shield:create-role "content manager" --guard=web
Create super user with full admin access
php artisan shield:create-superuser
Interactive mode (prompts for details)
php artisan shield:create-superuser
Non-interactive mode
php artisan shield:create-superuser --name="Site Administrator" --email="[email protected]" --password="secure-password-123"
Clear permission cache
php artisan shield:cache-reset bash
Create tenant-specific permission
php artisan shield:create-permission "manage inventory" --tenantId=1
Create tenant-specific role
php artisan shield:create-role "warehouse manager" --tenantId=1
Create superuser for specific tenant
php artisan shield:create-superuser --tenantId=1 bash
Show all roles and permissions
php artisan shield:show
Upgrade database for tenants feature
php artisan shield:upgrade-for-tenants
Custom commands you can create
php artisan make:command AssignBulkPermissions php artisan make:command SyncUserRoles php artisan make:command AuditPermissions bash
Clone the repository
git clone https://github.com/litepie/shield.git cd shield
Install dependencies
composer install
Run tests
composer test
Run code analysis
composer analyse
Run code formatting
composer format bash
Run all tests
composer test
Run specific test
./vendor/bin/phpunit tests/PermissionTest.php
Run with coverage
composer test-coverage
Role and Permission Queries
Advanced Queries
๐ก Events
Listen to role and permission changes throughout your application.
Enable Events
Available Events
Event Listeners
Example Listeners
Real-time Updates
๐ API Integration
Full support for API authentication and machine-to-machine communication.
Passport Integration
Enable Passport client credentials:
API Authentication
Machine-to-Machine
API Controllers
โก Performance & Caching
Optimized for high-performance applications with intelligent caching.
Cache Configuration
Cache Management
Performance Tips
Laravel Octane Support
Shield is fully compatible with Laravel Octane:
โ๏ธ Artisan Commands
License
The MIT License (MIT). Please see License File for more information.
๐ Support
- Documentation: Full documentation
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Security: Please email [email protected] for security vulnerabilities
๐ฏ Roadmap
- [ ] Vue.js Components: Pre-built permission components
- [ ] React Components: Permission management components
- [ ] GraphQL Support: GraphQL permission checking
- [ ] Audit Trails: Built-in permission change logging
- [ ] Permission Import/Export: Bulk permission management
- [ ] Advanced Caching: Multi-layer caching strategies
- [ ] Performance Dashboard: Permission usage analytics
Made with โค๏ธ by Litepie
Shield - Your Laravel application's guardian angel for role and permission management.
All versions of shield with dependencies
illuminate/support Version ^10.0|^11.0|^12.0
illuminate/database Version ^10.0|^11.0|^12.0
illuminate/contracts Version ^10.0|^11.0|^12.0
illuminate/auth Version ^10.0|^11.0|^12.0
illuminate/cache Version ^10.0|^11.0|^12.0
illuminate/console Version ^10.0|^11.0|^12.0