Download the PHP package abdulbaset/laravel-accessify without Composer
On this page you can find all versions of the php package abdulbaset/laravel-accessify. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abdulbaset/laravel-accessify
More information about abdulbaset/laravel-accessify
Files in abdulbaset/laravel-accessify
Package laravel-accessify
Short Description A Laravel package for managing roles and permissions
License MIT
Informations about the package laravel-accessify
Laravel Accessify
A simple and flexible package for handling roles and permissions in Laravel applications.
Why Accessify?
The Name
The name Accessify is derived from the word "Access", which reflects the core concept of the package — controlling access to system resources through roles and permissions. The suffix "-ify" gives the name a modern and dynamic feel, indicating that the package helps you apply access control rules in a flexible and efficient way.
The Concept
Just like a security guard who determines who can enter a building and what areas they can access, Accessify helps you manage who can do what in your Laravel application — using a simple and expressive Role-Based Access Control (RBAC) system.
In short: Accessify = "Control access with simplicity and power".
Why Choose Accessify?
- Simplicity: Easy to set up and use with minimal configuration
- Flexibility: Adapts to your application's needs with customizable roles and permissions
- Performance: Lightweight and optimized for speed
- Laravel Integration: Built specifically for Laravel with best practices in mind
- Active Maintenance: Regularly updated and maintained
Requirements
- PHP 8.1 or higher
- Laravel 10.x, 11.x, or 12.x
Features
- Role-based access control (RBAC)
- Permission management
- Blade directives for easy role and permission checks in views
- Artisan commands for managing roles and permissions
- Support for multiple roles per user
- Lightweight and easy to integrate
Installation
-
Install the package via Composer:
-
Publish the configuration file (optional):
- Run the migrations:
Note: The migrations will run automatically from the package. If you need to modify them, you can publish them using:
Configuration
You can customize the package by publishing the configuration file:
Artisan Commands
1. Managing Roles
Seed Roles (Safe ✅)
This command will safely seed roles from your config file. It will:
- Create any new roles from your config file
- Create missing permissions for roles
- Add missing permissions to roles
- Never delete any roles, even if they're not in your config file
Sync Roles (Dangerous ⚠️)
This command will synchronize roles between your config file and database. It will:
- Delete any roles not in your config file
- Create all roles from your config file
- Create missing permissions for roles
- Add missing permissions to roles
2. Managing Permissions
Seed Permissions (Safe ✅)
This command will safely seed permissions from your config file. It will:
- Create any new permissions from your config file
- Never delete any permissions, even if they're not in your config file
Sync Permissions (Dangerous ⚠️)
This command will synchronize permissions between your config file and database. It will:
- Delete any permissions not in your config file
- Create all permissions from your config file
When to Use Each Command
| Command | Safe? | Best For |
|---|---|---|
accessify:roles:seed |
✅ Safe | Initial setup or adding new roles without affecting existing ones |
accessify:roles:sync |
⚠️ Dangerous | Cleaning up old roles and ensuring database matches config exactly |
accessify:permissions:seed |
✅ Safe | Adding new permissions without affecting existing ones |
accessify:permissions:sync |
⚠️ Dangerous | Cleaning up old permissions and ensuring database matches config exactly |
Recommended Workflow
- Use the safe
accessify:roles:seedandaccessify:permissions:seedfor normal development - Only use
accessify:roles:syncandaccessify:permissions:syncwhen you need to clean up old data - Always backup your database before running sync commands
- In production, consider running sync commands in a controlled manner after thorough testing
Usage
Add HasRoles Trait to User Model
Add the HasRoles trait to your User model:
Important: Each user can have only one role. The system enforces this constraint at the database level.
Built-in Middleware
This package includes three middleware classes that are automatically registered with the service provider. These provide out-of-the-box protection for your routes.
Available Middleware
- Role Middleware - Restrict access to users with a specific role
- Permission Middleware - Restrict access to users with a specific permission
- Role or Permission Middleware - Restrict access to users with either a specific role or permission
Usage in Routes
Use the built-in middleware directly in your route definitions like this:
Usage in Controllers
You can also apply middleware in your controller's constructor:
-
Laravel 10.x (Source: Laravel 10.x Documentation)
-
Laravel 11.x (Source: Laravel 11.x Documentation)
- Laravel 12.x (Source: Laravel 12.x Documentation)
Multiple Roles/Permissions
You can specify multiple roles or permissions by separating them with a comma:
Middleware Groups
You can also use these middleware in route groups:
Available Methods
User Model Methods
Role Model Methods
Permission Model Methods
Example Usage:
Role Model Methods
Permissions Methods
Using getPermissions()
Authorization Methods
1. Using FormRequest
You can check permissions directly in your FormRequest classes:
2. Using Policies
-
First, create a policy:
-
Implement the policy methods:
- Register the policy in
AuthServiceProvider:
3. Using Custom Middleware
If you need more complex authorization logic, you can create custom middleware. Here's an example of creating a custom permission middleware:
-
Create the middleware:
-
Implement the middleware:
- Register the middleware:
For Laravel 10
Register in app/Http/Kernel.php:
For Laravel 11 & 12
Register in bootstrap/app.php:
- Use the custom middleware in your routes:
This approach gives you the flexibility to:
- Extend or create custom middleware for complex authorization logic
- Maintain clear separation between package features and custom code
4. Directly in Controller
You can also check permissions directly in your controller methods:
Blade Directives
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.