techlify-inc/laravel-rbac is a Laravel package for role based access control for laravel.
It currently has 1 GitHub stars and 252 downloads on Packagist (latest version 1.2.2).
Install it with composer require techlify-inc/laravel-rbac.
Discover more Laravel packages by techlify-inc
or browse all Laravel packages to compare alternatives.
Last updated
Just another Role Based Access Control package for Laravel. This one focuses on keeping things simple & sweet.
Install this package with composer using the following command:
composer require techlify-inc/laravel-rbac
Run migrations
$ php artisan migrate
Add the Rbac trait to your User model
class User extends Authenticatable
{
use TechlifyInc\LaravelRbac\Traits\LaravelRbac;
}
use \TechlifyInc\LaravelRbac\Models\Role;
$adminRole = Role::create([
'name' => 'Administrator',
'slug' => 'admin'
]);
$managerRole = Role::create([
'name' => 'Manager',
'slug' => 'manager'
]);
You can simple attach role to user:
use App\User;
$user = User::find(1);
$user->attachRole($adminRole);
//or you can attach using the role slug
$user->attachRole("admin");
And the same if you want to detach role:
$user->detachRole($adminRole);
//or you can remove using the role slug
$user->detachRole("admin");
You can simple check if user has role:
use App\User;
$user = User::find(1);
if ($user->hasRole('admin')) {
}
use \TechlifyInc\LaravelRbac\Models\Permission;
$createPermission = Permission::create([
'name' => 'Create product',
'slug' => 'product.create'
]);
$removePermission = Permission::create([
'name' => 'Delete product',
'slug' => 'product.remove'
]);
You can attach permission to role very simple:
use \TechlifyInc\LaravelRbac\Models\Role;
$adminRole = Role::find(1);
$adminRole->attachPermission($createPermission);
//or you can insert only slug
$adminRole->attachPermission("product.create");
And the same to detach permission:
$adminRole->detachPermission($createPermission);
$adminRole->detachPermission("product.create");
You can simple check if user has permission:
use App\User;
$user = User::find(1);
if ($user->hasPermission('product.create')) {
}
// OR for currently logged in user
if (auth()->user()->hasPermission('product.create'))
You can also enforce permissions at route level using the middleware (v0.2 onwards):
Route::get("customers", "CustomerController@index")->middleware("LaravelRbacEnforcePermission:customer_view");
A simple package for Laravel that provides user management services
Install this package with composer using the following command:
composer require techlify-inc/laravel-user-management
Run migrations
$ php artisan migrate
This package provides the following API services that your frontend can use:
// Get the set of users
GET api/users
// Get a single user
GET api/users/{id}
// Add a new user
POST api/users
// Update a user record
PATCH api/users/{id}
// Delete a user record
DELETE api/users/{id}
// Change the current user password
POST api/user/current/update-password {current_password, new_password}
// Log out the currently logged in user
POST api/user/logout
// Get the User record of the currently logged in user
GET api/user/current