almas / laravel-permission
A dynamic role and permission system designed to reduce development time.
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
pkg:composer/almas/laravel-permission
Requires
- php: ^8.2
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-ray: ^1.35
README
Installation
You can install the package via Composer:
composer require almas/laravel-permission
Set Super Admin Set the Super Admin email in your .env file:
SUPER_ADMIN_EMAIL=superadmin@gmail.com
- If not defined, the default is superadmin@gmail.com.
- A random password is automatically generated for the Super Admin.
- You can reset the password via the "Forgot Password" option
After installation, run the following Artisan command to set up everything:
php artisan permission
This command will:
- Run necessary database migrations
- Seed default roles and permissions automatically
No additional setup is required — you're ready to go!
Publish Configuration File
To publish the configuration file for this package, run the following command:
php artisan vendor:publish --tag=permission-config
Super Admin Features
- Only the Super Admin can create and delete permissions.
- For every new permission added to the system, the Super Admin is automatically granted that permission.
Route Registration
Add the following line to your routes/web.php file:
use Illuminate\Support\Facades\Route; Route::permission();
- By default, all routes will be protected using the auth middleware.
- This will automatically register all necessary permission management routes.
Route Prefix Behavior
- When using Route::permission();, the base route will be:
{your-app-url}/permissions
- You can customize the base route prefix by passing a parameter to the Route::permission() method:
Route::permission('custom-prefix');
- This will change the base route to:
{your-app-url}/custom-prefix
Blade Helper to Get Base Permission URL
@PermissionLink
Usage
- Get All Permissions (as array):
user_permission()
- Check a Single Permission: (eg. true/false):
user_permission('show-users')
- Blade Directives:
@user_permission('show-users') <a>Show Users</a> @end_user_permission
License
The MIT License (MIT). Please see License File for more information.