2017 © Pedro Peláez
 

package laravel-rbac

Role Based Access Control for Laravel

image

techlify-inc/laravel-rbac

Role Based Access Control for Laravel

  • Monday, April 9, 2018
  • by JoshuaKissoon
  • Repository
  • 1 Watchers
  • 1 Stars
  • 33 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 200 % Grown

The README.md

LaravelRbac

Just another Role Based Access Control package for Laravel. This one focuses on keeping things simple & sweet., (*1)

Installation

Install this package with composer using the following command:, (*2)

composer require techlify-inc/laravel-rbac

Run migrations, (*3)

$ php artisan migrate

Add the Rbac trait to your User model, (*4)


class User extends Authenticatable { use TechlifyInc\LaravelRbac\Traits\LaravelRbac; }

Usage

Roles

Creating roles

use \TechlifyInc\LaravelRbac\Models\Role;

$adminRole = Role::create([
    'name' => 'Administrator',
    'slug' => 'admin'
]);

$managerRole = Role::create([
    'name' => 'Manager',
    'slug' => 'manager'
]);

Assigning And Removing Roles

You can simple attach role to user:, (*5)

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:, (*6)

$user->detachRole($adminRole);
//or you can remove using the role slug
$user->detachRole("admin");

Checking for roles

You can simple check if user has role:, (*7)

use App\User;

$user = User::find(1);
if ($user->hasRole('admin')) {

}

Permissions

Creating permissions

use \TechlifyInc\LaravelRbac\Models\Permission;

$createPermission = Permission::create([
    'name' => 'Create product',
    'slug' => 'product.create'
]);

$removePermission = Permission::create([
    'name' => 'Delete product',
    'slug' => 'product.remove'
]);

Attaching And Detaching permissions

You can attach permission to role very simple:, (*8)

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:, (*9)

$adminRole->detachPermission($createPermission);
$adminRole->detachPermission("product.create");

Checking for permissions

You can simple check if user has permission:, (*10)

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):, (*11)

Route::get("customers", "CustomerController@index")->middleware("LaravelRbacEnforcePermission:customer_view");

LaravelUserManagement is now merged into this package

A simple package for Laravel that provides user management services, (*12)

Installation

Install this package with composer using the following command:, (*13)

composer require techlify-inc/laravel-user-management

Run migrations, (*14)

$ php artisan migrate

Usage

This package provides the following API services that your frontend can use:, (*15)

User Management


// 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}

User Password Management


// Change the current user password POST api/user/current/update-password {current_password, new_password}

User Session Management


// 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

The Versions

09/04 2018

dev-master

9999999-dev

Role Based Access Control for Laravel

  Sources   Download

MIT

by Techlify Inc.

09/04 2018

0.3.0

0.3.0.0

Role Based Access Control for Laravel

  Sources   Download

MIT

by Techlify Inc.

07/04 2018

0.2.0

0.2.0.0

Role Based Access Control for Laravel

  Sources   Download

MIT

by Techlify Inc.

26/03 2018

0.1.0

0.1.0.0

Role Based Access Control for Laravel

  Sources   Download

MIT

by Techlify Inc.