techexim/authorization

This package is abandoned and no longer maintained. No replacement package was suggested.

Roles & Permissions Authorization Scheme

1.2.1 2015-12-28 06:44 UTC

This package is not auto-updated.

Last update: 2019-12-20 03:25:26 UTC


README

This package is a package to provide Roles & Permissions management for any kind of objects, at this moment, it is designed to use for Laravel 5

Installation

Use composer to download the package

composer require techexim/authorization

Add Service Provider to Laravel application

TechExim\Auth\AuthServiceProvider::class,

You might need to publish default migrations and configuration

php artisan vendor:publish

How to use

Guard

Guard is a simple implemented service which provides simplest way to check permission of a subject on an object

use TechExim\Auth\Contracts\Guard;

class MyController extends Controller
{
	public function postAuth(Guard $guard)
	{
		// Check permissions of a subject
		// Both subject and object must implement TechExim\Auth\Contracts\Item
		$guard->hasPermissionTo($subject, 'section.action', $object);
	}
}

Roles

use TechExim\Auth\Contracts\Role\Repository as RoleRepository;

class MyController extends Controller
{
	public function postRole(RoleRepository $roleRepository)
	{
		// Add a new role
		$roleRepository->create('my_role');
	
		// Assign role to an object
		// Object must implement TechExim\Auth\Contracts\Item
		$roleRepository->assignItemRoleName($object, 'my_role');

		// Assign role to a subject on an object
		// Both subject and object must implement TechExim\Auth\Contracts\Item
		$roleRepository->assignObjectRoleName($subject, 'my_role', $object);

		// Get all assigned roles of an object
		$roleRepository->getItemRoles($object);

		// Check if a subject has a particular role on an object
		$roleRepository->hasObjectRoleName($subject, 'my_role', $object);

		// Remove subject's role on an object
		$roleRepository->removeObjectRoleName($subject, 'my_role', $object);
	}
}

Permissions

use TechExim\Auth\Contracts\Permission\Repository as PermissionRepository;

class MyController extends Controller
{
	public function postPermission(PermissionRepository $permissionRepository)
	{
		// A new permission
		$permissionRepository->create('section.action');

		// Assign permission to a subject on an object
		// Both subject and object must implement TechExim\Auth\Contracts\Item
		$permissionRepository->assignObjectPermissionName($subject, 'section.action', $object);

		// Check whether a subject has permission on an object
		$permissionRepository->hasObjectPermissionName($subject, 'section.action', $object);
	}
}

License

The Laravel Authorization is open-sourced software licensed under the MIT license