| Install | |
|---|---|
composer require wovosoft/laravel-permissions |
|
| Latest Version: | v1.0.6 |
| PHP: | >=7.3 |
The package is a Front-End Implementationf of the spatie/laravel-permission package. The spatie/laravel-permission is an awesome package for managing Roles & Permissionf for Laravel applications out of the box. But currently it doesn't have the front-end to easily deploy in your application.
This package comes to solve this problem. The package implements almost every features provided by spatie/laravel-permission.
Install via composer
composer require wovosoft/laravel-permissions
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="config"
resources/laravel-permissions/permissions folder. You need to add the Main.vue component to your app.jsphp artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="resources"
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="migrations"
php artisan vendor:publish --provider="Wovosoft\LaravelPermissions\ServiceProvider" --tag="seeds"
App\User.php model add the HasRoles.php Trait.//other imports goes here
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasRoles;
// other codes goes here
}
php artisan migrate
config/laravel-permissions.php . Add Default Permissions and Roles.<?php
return [
"route_name_prefix" => "Wovosoft",
"route_url_prefix" => "backend",
"middleware" => ["web", "auth"],
"users_table" => "users", //Default Laravel Generated Name
"roles_table" => config("permission.table_names.roles"), //comes from spatie config file.
"permissions_table" => config("permission.table_names.permissions"), //comes from spatie config file
"default_permissions" => [
[
"name" => "add user",
"description" => "Can Add User"
],
[
"name" => "edit user",
"description" => "Can Edit User"
],
[
"name" => "delete user",
"description" => "Can Delete User"
]
],
"default_roles" => [
[
"name" => "Super Admin",
"description" => "Super Admin Manages Everything"
],
[
"name" => "User",
"description" => "User Role"
],
[
"name" => "Customer",
"description" => "Customer Role"
]
]
];
backend, so your other routes should't be prefixed by backend. But you can change it in config/laravel-permissions.php config file. To check the registered routes, run in your terminal from project the root,php artisan route:list
config/laravel-permissions.php (#3) you can perform user abilities as follows:if(auth()->can('permission')){
echo "Auth user is allowed to perform this operation";
}
if(App\User::find(1)->can('permission')){
echo "Auth user is allowed to perform this operation";
}
$role = Wovosoft\LaravelPermissions\Models\Roles::find(1);
if($role->hasAbility('permission')){
echo "The Role with ID 1 is allowed to perform this operation";
}
Please keep in mind, the default Role and Permission models provided by spatie/laravel-permission are extended in the package. That's why rather than using
Spatie\Permission\Models\Rolefor Role andSpatie\Permission\Models\Permissionplease useWovosoft\LaravelPermissions\Models\Rolesfor Role andWovosoft\LaravelPermissions\Models\Permissionsfor Permission respectively.
Click here to check the demo project https://github.com/wovosoft/laravel-permissions-example
If you discover any security related issues, please email narayanadhikary24@gmail.com or create issue in the Github Repository.
This package is bootstrapped with the help of wovosoft/crud.